Skip to content

Commit

Permalink
perf(gatsby-source-contentful): do not linear search on a potentially…
Browse files Browse the repository at this point in the history
… large set (#27447)
  • Loading branch information
pvdz authored Oct 15, 2020
1 parent 0db2074 commit 9d304ed
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,25 +333,23 @@ exports.sourceNodes = async (
// Create a map of up to date entries and assets
function mergeSyncData(previous, current, deleted) {
const entryMap = new Map()
previous.forEach(
e => !deleted.includes(e.sys.id) && entryMap.set(e.sys.id, e)
)
current.forEach(
e => !deleted.includes(e.sys.id) && entryMap.set(e.sys.id, e)
)
previous.forEach(e => !deleted.has(e.sys.id) && entryMap.set(e.sys.id, e))
current.forEach(e => !deleted.has(e.sys.id) && entryMap.set(e.sys.id, e))
return [...entryMap.values()]
}

const deletedSet = new Set(currentSyncData.deletedEntries.map(e => e.sys.id))

const mergedSyncData = {
entries: mergeSyncData(
previousSyncData.entries,
currentSyncData.entries,
currentSyncData.deletedEntries.map(e => e.sys.id)
deletedSet
),
assets: mergeSyncData(
previousSyncData.assets,
currentSyncData.assets,
currentSyncData.deletedAssets.map(e => e.sys.id)
deletedSet
),
}

Expand Down

0 comments on commit 9d304ed

Please sign in to comment.