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

fix(gatsby): use lmdb for resultHash cache so shared across workers #34925

Merged
merged 10 commits into from
Mar 11, 2022
10 changes: 7 additions & 3 deletions packages/gatsby/src/query/query-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { GraphQLRunner } from "./graphql-runner"
import { IExecutionResult, PageContext } from "./types"
import { pageDataExists, savePageQueryResult } from "../utils/page-data"

const resultHashes = new Map()
const GatsbyCacheLmdbImpl = require(`../utils/cache-lmdb`).default
pieh marked this conversation as resolved.
Show resolved Hide resolved
const resultHashCache = new GatsbyCacheLmdbImpl({
name: `query-result-hashes`,
encoding: `string`,
}).init()
pieh marked this conversation as resolved.
Show resolved Hide resolved

export interface IQueryJob {
id: string
Expand Down Expand Up @@ -172,11 +176,11 @@ export async function queryRunner(
.digest(`base64`)

if (
resultHash !== resultHashes.get(queryJob.id) ||
resultHash !== (await resultHashCache.get(queryJob.id)) ||
(queryJob.isPage &&
!pageDataExists(path.join(program.directory, `public`), queryJob.id))
) {
resultHashes.set(queryJob.id, resultHash)
resultHashCache.set(queryJob.id, resultHash)
pieh marked this conversation as resolved.
Show resolved Hide resolved

if (queryJob.isPage) {
// We need to save this temporarily in cache because
Expand Down