Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(gatsby): Create one promise per queue, not one per job #20606

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions packages/gatsby/src/query/queue.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ const createDevelopQueue = getRunner => {
return queue return queue
} }


const pushJob = (queue, job) =>
new Promise((resolve, reject) =>
queue
.push(job)
.on(`finish`, resolve)
.on(`failed`, reject)
)

/** /**
* Returns a promise that pushes jobs onto queue and resolves onces * Returns a promise that pushes jobs onto queue and resolves onces
* they're all finished processing (or rejects if one or more jobs * they're all finished processing (or rejects if one or more jobs
Expand All @@ -100,15 +92,19 @@ const processBatch = async (queue, jobs, activity) => {
return Promise.resolve() return Promise.resolve()
} }


const runningJobs = jobs.map(job => return new Promise((resolve, reject) => {
pushJob(queue, job).then(v => {
if (activity.tick) { if (activity.tick) {
activity.tick() queue.on(`task_finish`, () => activity.tick())
} }
return v
queue
// Note: the first arg is the path, the second the error
.once(`task_failed`, (...err) => reject(err))
// Note: `drain` fires when all tasks _finish_, `empty` fires when queue is empty (but tasks are still running)
.once(`drain`, resolve)

jobs.forEach(job => queue.push(job))
}) })
)
return Promise.all(runningJobs)
} }


module.exports = { module.exports = {
Expand Down