Skip to content

Commit

Permalink
fix(gatsby-source-drupal): cache backlink records (#33444)
Browse files Browse the repository at this point in the history
* fix(gatsby-source-drupal): check relationships type exists on node before filtering (#33181) (#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 <[email protected]>

* format

Co-authored-by: Dustin Schau <[email protected]>
(cherry picked from commit d4f8355)

Co-authored-by: Kyle Mathews <[email protected]>

* chore(release): Publish

 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]

* 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 <[email protected]>
Co-authored-by: Vladimir Razuvaev <[email protected]>
Co-authored-by: Krzysztof Szot <[email protected]>
  • Loading branch information
4 people authored Oct 25, 2021
1 parent 4b6d04b commit 0def3ac
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/gatsby-source-drupal/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ jest.mock(`gatsby-source-filesystem`, () => {
}
})

function makeCache() {
const store = new Map()
return {
get: async id => store.get(id),
set: async (key, value) => store.set(key, value),
store,
}
}

const normalize = require(`../normalize`)
const downloadFileSpy = jest.spyOn(normalize, `downloadFile`)

Expand Down Expand Up @@ -75,6 +84,7 @@ describe(`gatsby-source-drupal`, () => {
store,
getNode: id => nodes[id],
getNodes,
cache: makeCache(),
}

beforeAll(async () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const { setOptions, getOptions } = require(`./plugin-options`)

const { nodeFromData, downloadFile, isFileNode } = require(`./normalize`)
const {
initRefsLookups,
storeRefsLookups,
handleReferences,
handleWebhookUpdate,
handleDeletedNode,
Expand Down Expand Up @@ -150,6 +152,8 @@ exports.sourceNodes = async (
} = pluginOptions
const { createNode, setPluginStatus, touchNode } = actions

await initRefsLookups({ cache, getNode })

// Update the concurrency limit from the plugin options
requestQueue.concurrency = concurrentAPIRequests

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

changesActivity.end()
await storeRefsLookups({ cache })
return
}

Expand Down Expand Up @@ -232,6 +237,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
return
}
changesActivity.end()
await storeRefsLookups({ cache })
return
}

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

drupalFetchIncrementalActivity.end()
fastBuildsSpan.finish()
await storeRefsLookups({ cache })
return
}

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

if (!requireFullRebuild) {
await storeRefsLookups({ cache })
return
}
}
Expand Down Expand Up @@ -635,6 +643,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
initialSourcing = false

createNodesSpan.finish()
await storeRefsLookups({ cache, getNodes })
return
}

Expand Down
38 changes: 35 additions & 3 deletions packages/gatsby-source-drupal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,38 @@ const {

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

const backRefsNamesLookup = new Map()
const referencedNodesLookup = new Map()
let backRefsNamesLookup = new Map()
let referencedNodesLookup = new Map()

const initRefsLookups = async ({ cache }) => {
const backRefsNamesLookupStr = await cache.get(`backRefsNamesLookup`)
const referencedNodesLookupStr = await cache.get(`referencedNodesLookup`)

if (backRefsNamesLookupStr) {
backRefsNamesLookup = new Map(JSON.parse(backRefsNamesLookupStr))
}

if (referencedNodesLookupStr) {
referencedNodesLookup = new Map(JSON.parse(referencedNodesLookupStr))
}
}

exports.initRefsLookups = initRefsLookups

const storeRefsLookups = async ({ cache }) => {
await Promise.all([
cache.set(
`backRefsNamesLookup`,
JSON.stringify(Array.from(backRefsNamesLookup.entries()))
),
cache.set(
`referencedNodesLookup`,
JSON.stringify(Array.from(referencedNodesLookup.entries()))
),
])
}

exports.storeRefsLookups = storeRefsLookups

const handleReferences = (
node,
Expand Down Expand Up @@ -333,7 +363,9 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
}
node.internal.contentDigest = createContentDigest(node)
createNode(node)
reporter.log(`Updated Gatsby node: ${node.id}`)
reporter.log(
`Updated Gatsby node: id: ${node.id} — type: ${node.internal.type}`
)
}
}

Expand Down

0 comments on commit 0def3ac

Please sign in to comment.