From a60bd0a7b6b112c03bd4066150e4098ee25578ee Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Mon, 30 Nov 2020 15:32:09 +0100 Subject: [PATCH] perf(gatsby-source-contentful): fix unguided search in loop over large lists --- 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(