Skip to content

Commit 2500324

Browse files
authored
feat(gatsby-source-wordpress): PQR support (#32779)
* we only want to check plugin requirements during initial boot up * allow ingestRemoteSchema to run more than once per 10 seconds when not in development
1 parent 7116ab5 commit 2500324

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

packages/gatsby-source-wordpress/src/steps/check-plugin-requirements.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,12 @@ ${data.generalSettings.url}/wp-admin/options-permalink.php.
285285
const ensurePluginRequirementsAreMet = async (
286286
helpers: NodePluginArgs
287287
): Promise<void> => {
288-
if (helpers.traceId === `refresh-createSchemaCustomization`) {
288+
if (
289+
helpers.traceId === `refresh-createSchemaCustomization` ||
290+
// PQR doesn't have a trace id.
291+
// By the time this runs in PQR we don't need it to run again.
292+
!helpers.traceId
293+
) {
289294
return
290295
}
291296

packages/gatsby-source-wordpress/src/steps/ingest-remote-schema/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ import { cacheFetchedTypes } from "./cache-fetched-types"
1010
import { writeQueriesToDisk } from "./write-queries-to-disk"
1111

1212
const ingestRemoteSchema = async (helpers, pluginOptions) => {
13-
const schemaTimeKey = `lastIngestRemoteSchemaTime`
14-
const lastIngestRemoteSchemaTime = await helpers.cache.get(schemaTimeKey)
15-
16-
const ingestedSchemaInLastTenSeconds =
17-
Date.now() - lastIngestRemoteSchemaTime <= 10000
18-
19-
if (lastIngestRemoteSchemaTime && ingestedSchemaInLastTenSeconds) {
20-
// only allow this to run once every ten seconds
21-
// this prevents thrashing when many webhooks are received at once
22-
return
13+
if (process.env.NODE_ENV === `development`) {
14+
// running this code block in production is problematic for PQR
15+
// since this fn will run once for each worker and we need the result in each
16+
// we'll return early in most workers when it checks the cache here
17+
// Since PQR doesn't run in development and this code block was only meant for dev
18+
// it should be ok to wrap it in this if statement
19+
const schemaTimeKey = `lastIngestRemoteSchemaTime`
20+
const lastIngestRemoteSchemaTime = await helpers.cache.get(schemaTimeKey)
21+
22+
const ingestedSchemaInLastTenSeconds =
23+
Date.now() - lastIngestRemoteSchemaTime <= 10000
24+
25+
if (lastIngestRemoteSchemaTime && ingestedSchemaInLastTenSeconds) {
26+
// only allow this to run once every ten seconds
27+
// this prevents thrashing when many webhooks are received at once
28+
return
29+
}
30+
31+
await helpers.cache.set(schemaTimeKey, Date.now())
2332
}
2433

25-
await helpers.cache.set(schemaTimeKey, Date.now())
26-
2734
const activity = helpers.reporter.activityTimer(
2835
formatLogMessage(`ingest WPGraphQL schema`)
2936
)

0 commit comments

Comments
 (0)