Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gatsby-source-contentful): remove unnecessary check for existing node #34829

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 0 additions & 89 deletions packages/gatsby-source-contentful/src/__tests__/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 0 additions & 7 deletions packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down