-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce excess file system writes by implementing query queue (#3237)
* Reduce excess file system writes by implementing query queue There are multiple ways that running queries can be triggered. Previous to this PR, Gatsby had done some de-duping of queries but in practice, queries for pages/layouts can often be running multiple times in short succession. This is normally fine-ish but @Gaeron was running into troubles while editing markdown on reactjs.org where webpack would error when it detected a change in a file and before it could read it, Gatsby would start writing to the file again before webpack could finish reading it resulting in a JSON.parse error due to the incomplete JSON. On top of this, Gatsby would write out the result of every query if even the query returned the same result as previously. To address these this PR adds a query queue that deduplicates added pages/layouts. This means we're writing out results far less often. Second we hash each query result and only write to file if the result has changed which means far less work for webpack and far faster hot reloading of query updates to the browser. * Add back bootstrapping repo to netlify build * yarn global add isn't working for some reason
- Loading branch information
1 parent
d27647a
commit ecc7e14
Showing
9 changed files
with
105 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/gatsby/src/internal-plugins/query-runner/query-queue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Queue = require(`better-queue`) | ||
|
||
const queryRunner = require(`./query-runner`) | ||
const { store } = require(`../../redux`) | ||
|
||
const queue = new Queue( | ||
(plObj, callback) => { | ||
const state = store.getState() | ||
return queryRunner(plObj, state.components[plObj.component]).then( | ||
result => callback(null, result), | ||
error => callback(error) | ||
) | ||
}, | ||
{ concurrent: 4 } | ||
) | ||
|
||
module.exports = queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters