Skip to content

Commit c3ef48c

Browse files
KyleAMathewsGatsbyJS Botvladarkszot-ref
authored andcommittedOct 29, 2021
fix(gatsby-source-drupal): cache backlink records (gatsbyjs#33444)
* fix(gatsby-source-drupal): check relationships type exists on node before filtering (gatsbyjs#33181) (gatsbyjs#33228) * fix(gatsby-source-drupal): check relationships type exists on node before filtering * Update packages/gatsby-source-drupal/src/utils.js Co-authored-by: Dustin Schau <DSchau@users.noreply.github.com> * format Co-authored-by: Dustin Schau <DSchau@users.noreply.github.com> (cherry picked from commit d4f8355) Co-authored-by: Kyle Mathews <mathews.kyle@gmail.com> * chore(release): Publish - babel-plugin-remove-graphql-queries@3.14.0 - babel-preset-gatsby-package@1.14.0 - babel-preset-gatsby@1.14.0 - create-gatsby@1.14.0 - gatsby-admin@0.24.0 - gatsby-cli@3.14.0 - gatsby-codemods@2.14.0 - gatsby-core-utils@2.14.0 - gatsby-cypress@1.14.0 - gatsby-design-tokens@3.14.0 - gatsby-dev-cli@3.14.0 - gatsby-graphiql-explorer@1.14.0 - gatsby-legacy-polyfills@1.14.0 - gatsby-link@3.14.0 - gatsby-page-utils@1.14.0 - gatsby-plugin-benchmark-reporting@1.14.0 - gatsby-plugin-canonical-urls@3.14.0 - gatsby-plugin-catch-links@3.14.0 - gatsby-plugin-coffeescript@3.14.0 - gatsby-plugin-create-client-paths@3.14.0 - gatsby-plugin-cxs@3.14.0 - gatsby-plugin-emotion@6.14.0 - gatsby-plugin-facebook-analytics@3.14.0 - gatsby-plugin-feed@3.14.0 - gatsby-plugin-flow@2.14.0 - gatsby-plugin-fullstory@3.14.0 - gatsby-plugin-gatsby-cloud@3.2.0 - gatsby-plugin-google-analytics@3.14.0 - gatsby-plugin-google-gtag@3.14.0 - gatsby-plugin-google-tagmanager@3.14.0 - gatsby-plugin-graphql-config@0.23.0 - gatsby-plugin-image@1.14.0 - gatsby-plugin-jss@3.14.0 - gatsby-plugin-layout@2.14.0 - gatsby-plugin-less@5.14.0 - gatsby-plugin-lodash@4.14.0 - gatsby-plugin-manifest@3.14.0 - gatsby-plugin-mdx@2.14.0 - gatsby-plugin-netlify-cms@5.14.0 - gatsby-plugin-no-sourcemaps@3.14.0 - gatsby-plugin-nprogress@3.14.0 - gatsby-plugin-offline@4.14.0 - gatsby-plugin-page-creator@3.14.0 - gatsby-plugin-postcss@4.14.0 - gatsby-plugin-preact@5.14.0 - gatsby-plugin-preload-fonts@2.14.0 - gatsby-plugin-react-css-modules@3.14.0 - gatsby-plugin-react-helmet@4.14.0 - gatsby-plugin-remove-trailing-slashes@3.14.0 - gatsby-plugin-sass@4.14.0 - gatsby-plugin-schema-snapshot@2.14.0 - gatsby-plugin-sharp@3.14.0 - gatsby-plugin-sitemap@4.10.0 - gatsby-plugin-styled-components@4.14.0 - gatsby-plugin-styled-jsx@4.14.0 - gatsby-plugin-styletron@6.14.0 - gatsby-plugin-stylus@3.14.0 - gatsby-plugin-subfont@3.14.0 - gatsby-plugin-twitter@3.14.0 - gatsby-plugin-typescript@3.14.0 - gatsby-plugin-typography@3.14.0 - gatsby-plugin-utils@1.14.0 - gatsby-react-router-scroll@4.14.0 - gatsby-recipes@0.25.0 - gatsby-remark-autolink-headers@4.11.0 - gatsby-remark-code-repls@5.11.0 - gatsby-remark-copy-linked-files@4.11.0 - gatsby-remark-custom-blocks@3.14.0 - gatsby-remark-embed-snippet@6.11.0 - gatsby-remark-graphviz@3.11.0 - gatsby-remark-images-contentful@4.11.0 - gatsby-remark-images@5.11.0 - gatsby-remark-katex@5.11.0 - gatsby-remark-prismjs@5.11.0 - gatsby-remark-responsive-iframe@4.11.0 - gatsby-remark-smartypants@4.11.0 - gatsby-source-contentful@5.14.0 - gatsby-source-drupal@4.14.0 - gatsby-source-faker@3.14.0 - gatsby-source-filesystem@3.14.0 - gatsby-source-graphql@3.14.0 - gatsby-source-hacker-news@3.14.0 - gatsby-source-lever@3.14.0 - gatsby-source-medium@3.14.0 - gatsby-source-mongodb@3.14.0 - gatsby-source-npm-package-search@3.14.0 - gatsby-source-shopify@5.6.0 - gatsby-source-wikipedia@3.14.0 - gatsby-source-wordpress@5.14.0 - gatsby-telemetry@2.14.0 - gatsby-transformer-asciidoc@2.14.0 - gatsby-transformer-csv@3.14.0 - gatsby-transformer-documentationjs@5.14.0 - gatsby-transformer-excel@3.14.0 - gatsby-transformer-hjson@3.14.0 - gatsby-transformer-javascript-frontmatter@3.14.0 - gatsby-transformer-javascript-static-exports@3.14.0 - gatsby-transformer-json@3.14.0 - gatsby-transformer-pdf@2.14.0 - gatsby-transformer-react-docgen@6.14.0 - gatsby-transformer-remark@4.11.0 - gatsby-transformer-screenshot@3.14.0 - gatsby-transformer-sharp@3.14.0 - gatsby-transformer-sqip@3.14.0 - gatsby-transformer-toml@3.14.0 - gatsby-transformer-xml@3.14.0 - gatsby-transformer-yaml@3.14.0 - gatsby-worker@0.5.0 - gatsby@3.14.0 * Preserve backlink/reference lookup tables in cache * test * fix bad merge * try try again * Improve log * Get working with tests Co-authored-by: GatsbyJS Bot <mathews.kyle+gatsbybot@gmail.com> Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com> Co-authored-by: Krzysztof Szot <kszot@reference.be>
1 parent 8f7784b commit c3ef48c

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed
 

‎packages/gatsby-source-drupal/src/__tests__/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ jest.mock(`gatsby-source-filesystem`, () => {
2020
}
2121
})
2222

23+
function makeCache() {
24+
const store = new Map()
25+
return {
26+
get: async id => store.get(id),
27+
set: async (key, value) => store.set(key, value),
28+
store,
29+
}
30+
}
31+
2332
const normalize = require(`../normalize`)
2433
const downloadFileSpy = jest.spyOn(normalize, `downloadFile`)
2534

@@ -75,6 +84,7 @@ describe(`gatsby-source-drupal`, () => {
7584
store,
7685
getNode: id => nodes[id],
7786
getNodes,
87+
cache: makeCache(),
7888
}
7989

8090
beforeAll(async () => {

‎packages/gatsby-source-drupal/src/gatsby-node.js

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const { setOptions, getOptions } = require(`./plugin-options`)
1212

1313
const { nodeFromData, downloadFile, isFileNode } = require(`./normalize`)
1414
const {
15+
initRefsLookups,
16+
storeRefsLookups,
1517
handleReferences,
1618
handleWebhookUpdate,
1719
handleDeletedNode,
@@ -150,6 +152,8 @@ exports.sourceNodes = async (
150152
} = pluginOptions
151153
const { createNode, setPluginStatus, touchNode } = actions
152154

155+
await initRefsLookups({ cache, getNode })
156+
153157
// Update the concurrency limit from the plugin options
154158
requestQueue.concurrency = concurrentAPIRequests
155159

@@ -202,6 +206,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
202206
}
203207

204208
changesActivity.end()
209+
await storeRefsLookups({ cache })
205210
return
206211
}
207212

@@ -232,6 +237,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
232237
return
233238
}
234239
changesActivity.end()
240+
await storeRefsLookups({ cache })
235241
return
236242
}
237243

@@ -362,6 +368,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
362368

363369
drupalFetchIncrementalActivity.end()
364370
fastBuildsSpan.finish()
371+
await storeRefsLookups({ cache })
365372
return
366373
}
367374

@@ -372,6 +379,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
372379
initialSourcing = false
373380

374381
if (!requireFullRebuild) {
382+
await storeRefsLookups({ cache })
375383
return
376384
}
377385
}
@@ -635,6 +643,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
635643
initialSourcing = false
636644

637645
createNodesSpan.finish()
646+
await storeRefsLookups({ cache, getNodes })
638647
return
639648
}
640649

‎packages/gatsby-source-drupal/src/utils.js

+35-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,38 @@ const {
99

1010
const { getOptions } = require(`./plugin-options`)
1111

12-
const backRefsNamesLookup = new Map()
13-
const referencedNodesLookup = new Map()
12+
let backRefsNamesLookup = new Map()
13+
let referencedNodesLookup = new Map()
14+
15+
const initRefsLookups = async ({ cache }) => {
16+
const backRefsNamesLookupStr = await cache.get(`backRefsNamesLookup`)
17+
const referencedNodesLookupStr = await cache.get(`referencedNodesLookup`)
18+
19+
if (backRefsNamesLookupStr) {
20+
backRefsNamesLookup = new Map(JSON.parse(backRefsNamesLookupStr))
21+
}
22+
23+
if (referencedNodesLookupStr) {
24+
referencedNodesLookup = new Map(JSON.parse(referencedNodesLookupStr))
25+
}
26+
}
27+
28+
exports.initRefsLookups = initRefsLookups
29+
30+
const storeRefsLookups = async ({ cache }) => {
31+
await Promise.all([
32+
cache.set(
33+
`backRefsNamesLookup`,
34+
JSON.stringify(Array.from(backRefsNamesLookup.entries()))
35+
),
36+
cache.set(
37+
`referencedNodesLookup`,
38+
JSON.stringify(Array.from(referencedNodesLookup.entries()))
39+
),
40+
])
41+
}
42+
43+
exports.storeRefsLookups = storeRefsLookups
1444

1545
const handleReferences = (
1646
node,
@@ -333,7 +363,9 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
333363
}
334364
node.internal.contentDigest = createContentDigest(node)
335365
createNode(node)
336-
reporter.log(`Updated Gatsby node: ${node.id}`)
366+
reporter.log(
367+
`Updated Gatsby node: id: ${node.id} — type: ${node.internal.type}`
368+
)
337369
}
338370
}
339371

0 commit comments

Comments
 (0)