Skip to content

Commit

Permalink
fix(gatsby): wait for LMDB upserts to finish before emitting ENGINES_…
Browse files Browse the repository at this point in the history
…READY (#34853) (#34896)

(cherry picked from commit b4637c0)

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
ViCo0TeCH and pieh committed Feb 22, 2022
1 parent f5705b9 commit 9a616c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/gatsby/src/commands/build.ts
Expand Up @@ -286,6 +286,9 @@ module.exports = async function build(
)
}

// Start saving page.mode in the main process (while queries run in workers in parallel)
const waitMaterializePageMode = materializePageMode()

let waitForWorkerPoolRestart = Promise.resolve()
if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
await runQueriesInWorkersQueue(workerPool, queryIds, {
Expand Down Expand Up @@ -322,6 +325,7 @@ module.exports = async function build(
}

if (process.send && shouldGenerateEngines()) {
await waitMaterializePageMode
process.send({
type: `LOG_ACTION`,
action: {
Expand Down Expand Up @@ -401,9 +405,6 @@ module.exports = async function build(

await waitForWorkerPoolRestart

// Start saving page.mode in the main process (while HTML is generated in workers in parallel)
const waitMaterializePageMode = materializePageMode()

const { toRegenerate, toDelete } =
await buildHTMLPagesAndDeleteStaleArtifacts({
program,
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/src/utils/page-mode.ts
Expand Up @@ -8,6 +8,7 @@ import {
import { reportOnce } from "./report-once"
import { ROUTES_DIRECTORY } from "../constants"
import { Runner } from "../bootstrap/create-graphql-runner"
import { getDataStore } from "../datastore"

type IPageConfigFn = (arg: { params: Record<string, unknown> }) => {
defer: boolean
Expand Down Expand Up @@ -111,6 +112,7 @@ export async function materializePageMode(): Promise<void> {
await new Promise(resolve => setImmediate(resolve))
}
}
await getDataStore().ready()
}

export async function preparePageTemplateConfigs(
Expand Down

0 comments on commit 9a616c0

Please sign in to comment.