Skip to content

Commit

Permalink
perf(gatsby-plugin-mdx): Stop clobbering the same file over and over …
Browse files Browse the repository at this point in the history
…again (#27974)

* perf(gatsby-plugin-mdx): Stop clobbering the same file over and over again

* Undo the await part, can be separate PR

Co-authored-by: gatsbybot <[email protected]>
(cherry picked from commit 3d100e3)
  • Loading branch information
pvdz authored and vladar committed Jan 5, 2021
1 parent afac774 commit 5d4851f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/gatsby-plugin-mdx/gatsby/on-create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ async function onCreateNodeLessBabel(
})
}

const writeCache = new Set()

async function cacheScope({
cache,
scopeImports,
Expand All @@ -169,6 +171,16 @@ async function cacheScope({
export default { ${scopeIdentifiers.join(`, `)} }`

// Multiple files sharing the same imports/exports will lead to the same file writes.
// Prevent writing the same content to the same file over and over again (reduces io pressure).
// This also prevents an expensive babel step whose outcome is based on this same value
if (writeCache.has(scopeFileContent)) {
return
}

// Make sure other calls see this value being processed during async time
writeCache.add(scopeFileContent)

// if parent node is a file, convert relative imports to be
// relative to new .cache location
if (parentNode.internal.type === `File`) {
Expand Down

0 comments on commit 5d4851f

Please sign in to comment.