From 7fa4b80bf60dd0e869a69a00f098c15aa9984af3 Mon Sep 17 00:00:00 2001 From: axe312ger Date: Wed, 16 Feb 2022 13:48:40 +0100 Subject: [PATCH] refactor(contentful): remove unnecessary check for existing node as we no more get merged datasets from old syncs and only new & changed nodes from Contentful, we do no more need this check. --- .../src/__tests__/normalize.js | 89 ------------------- .../gatsby-source-contentful/src/normalize.js | 7 -- 2 files changed, 96 deletions(-) diff --git a/packages/gatsby-source-contentful/src/__tests__/normalize.js b/packages/gatsby-source-contentful/src/__tests__/normalize.js index 2709c07332fd7..45d6699205c3b 100644 --- a/packages/gatsby-source-contentful/src/__tests__/normalize.js +++ b/packages/gatsby-source-contentful/src/__tests__/normalize.js @@ -272,95 +272,6 @@ describe(`Process contentful data (by name)`, () => { }) }) -describe(`Skip existing nodes in warm build`, () => { - it(`creates nodes for each entry`, () => { - const entryList = buildEntryList({ - currentSyncData, - contentTypeItems, - }) - - const resolvable = buildResolvableSet({ - assets: currentSyncData.assets, - entryList, - }) - - const foreignReferenceMap = buildForeignReferenceMap({ - contentTypeItems, - entryList, - resolvable, - defaultLocale, - space, - useNameForId: true, - }) - - const createNode = jest.fn() - const createNodeId = jest.fn(id => id) - let doReturn = true - const getNode = jest.fn(id => { - if (doReturn) { - doReturn = false - // Note: the relevant part for this test is that the same digest is returned - // so it skips generating the node and any of its children. Actual shape of - // returned is not relevant to test so update if anything breaks. - return { - id, - internal: { contentDigest: entryList[0][0].sys.updatedAt }, - } - } - // All other nodes are new ("unknown") - return undefined - }) - contentTypeItems.forEach((contentTypeItem, i) => { - createNodesForContentType({ - contentTypeItem, - restrictedNodeFields, - conflictFieldPrefix, - entries: entryList[i], - createNode, - createNodeId, - getNode, - resolvable, - foreignReferenceMap, - defaultLocale, - locales, - space, - useNameForId: true, - pluginConfig, - unstable_createNodeManifest, - }) - }) - - const nodeTypeCounts = countCreatedNodeTypesFromMock(createNode.mock) - - expect(Object.keys(nodeTypeCounts)).toHaveLength(15) - - expect(nodeTypeCounts).toEqual( - expect.objectContaining({ - ContentfulBrand: 6, - contentfulBrandCompanyDescriptionTextNode: 6, - contentfulBrandCompanyNameTextNode: 6, - // These 3 category entities matter as the first node is skipped in the test - ContentfulCategory: 3, - contentfulCategoryCategoryDescriptionTextNode: 3, - contentfulCategoryTitleTextNode: 3, - ContentfulContentType: 5, - ContentfulJsonTest: 2, - contentfulJsonTestJsonStringTestJsonNode: 2, - contentfulJsonTestJsonTestJsonNode: 2, - ContentfulProduct: 8, - contentfulProductProductDescriptionTextNode: 8, - contentfulProductProductNameTextNode: 8, - ContentfulRemarkTest: 2, - contentfulRemarkTestContentTextNode: 2, - }) - ) - - // Relevant to compare to compare warm and cold situation - // This number ought to be less than the cold build - expect(createNode.mock.calls.length).toBe(66) // "warm build where entry was not changed" count - }) -}) - describe(`Process existing mutated nodes in warm build`, () => { it(`creates nodes for each entry`, () => { const entryList = buildEntryList({ diff --git a/packages/gatsby-source-contentful/src/normalize.js b/packages/gatsby-source-contentful/src/normalize.js index adc6e976cd2b2..70f11142ca6f2 100644 --- a/packages/gatsby-source-contentful/src/normalize.js +++ b/packages/gatsby-source-contentful/src/normalize.js @@ -383,13 +383,6 @@ export const createNodesForContentType = ({ entryItem.sys.type ) - const existingNode = getNode(entryNodeId) - if (existingNode?.internal?.contentDigest === entryItem.sys.updatedAt) { - // The Contentful model has `.sys.updatedAt` leading for an entry. If the updatedAt value - // of an entry did not change, then we can trust that none of its children were changed either. - return null - } - // Get localized fields. const entryItemFields = _.mapValues(entryItem.fields, (v, k) => { const fieldProps = contentTypeItem.fields.find(