From 474dd36dffd8a7b3c06c25aa958517bc9b62fedb Mon Sep 17 00:00:00 2001 From: GatsbyJS Bot Date: Tue, 1 Dec 2020 07:45:46 -0500 Subject: [PATCH] perf(gatsby-source-contentful): fix unguided search in loop over large lists (#28375) (#28404) (cherry picked from commit d9904ac69ec6abcd8e16f18056b0387c54d8c625) Co-authored-by: Peter van der Zee <209817+pvdz@users.noreply.github.com> --- packages/gatsby-source-contentful/src/gatsby-node.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-contentful/src/gatsby-node.js b/packages/gatsby-source-contentful/src/gatsby-node.js index 173f227cd23f3..f1563bf6a8a4d 100644 --- a/packages/gatsby-source-contentful/src/gatsby-node.js +++ b/packages/gatsby-source-contentful/src/gatsby-node.js @@ -499,17 +499,17 @@ exports.sourceNodes = async ( reporter.verbose(`Resolving Contentful references`) - const newOrUpdatedEntries = [] + const newOrUpdatedEntries = new Set() entryList.forEach(entries => { entries.forEach(entry => { - newOrUpdatedEntries.push(`${entry.sys.id}___${entry.sys.type}`) + newOrUpdatedEntries.add(`${entry.sys.id}___${entry.sys.type}`) }) }) // Update existing entry nodes that weren't updated but that need reverse // links added. existingNodes - .filter(n => _.includes(newOrUpdatedEntries, `${n.id}___${n.sys.type}`)) + .filter(n => newOrUpdatedEntries.has(`${n.id}___${n.sys.type}`)) .forEach(n => { if (foreignReferenceMap[`${n.id}___${n.sys.type}`]) { foreignReferenceMap[`${n.id}___${n.sys.type}`].forEach(