Skip to content

Commit

Permalink
use lmdb for resultHash cache so shared across workers
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Oct 26, 2021
1 parent c25860f commit 7c51853
Showing 1 changed file with 7 additions and 3 deletions.
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
const resultHashCache = new GatsbyCacheLmdbImpl({
name: `query-result-hashes`,
encoding: `string`,
}).init()

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)

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

0 comments on commit 7c51853

Please sign in to comment.