Skip to content

Commit

Permalink
Add node.id to cache id to avoid cache collissions if the nodes have …
Browse files Browse the repository at this point in the history
…identical content fixes #4385 (#4388)

* Add node.id to cache id to avoid cache collissions if the nodes have identical content fixes #4385

* Fix creating contentDigest for MarkdownRemark nodes so includes all data
  • Loading branch information
KyleAMathews committed Mar 6, 2018
1 parent 5b715d2 commit 4faec67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ date: \\"2017-09-18T23:19:51.246Z\\"
---
Where oh where is my little pony?
",
"contentDigest": "8062733a090dc2fca383c268ae549f71",
"contentDigest": "c28ae5f9cd5d74e0697ce8a0e8ff5715",
"type": "MarkdownRemark",
},
"parent": "whatever",
Expand Down Expand Up @@ -50,7 +50,7 @@ date: \\"2017-09-18T23:19:51.246Z\\"
---
Where oh where is my little pony?
",
"contentDigest": "8062733a090dc2fca383c268ae549f71",
"contentDigest": "c28ae5f9cd5d74e0697ce8a0e8ff5715",
"type": "MarkdownRemark",
},
"parent": "whatever",
Expand Down Expand Up @@ -108,7 +108,7 @@ Sed eu gravida mauris. Suspendisse potenti. Praesent sit amet egestas mi, sed he
Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat mattis dui nec pretium. Donec vel consectetur est. Nam sagittis, libero vitae pretium pharetra, velit est dignissim erat, at cursus quam massa vitae ligula. Suspendisse potenti. In hac habitasse platea dictumst. Donec sit amet finibus justo. Mauris ante dolor, pulvinar vitae feugiat eu, rhoncus nec diam. In ut accumsan diam, faucibus fringilla odio. Nunc id ultricies turpis. Quisque justo quam, tristique sit amet interdum quis, facilisis at mi. Fusce porttitor vel sem ut condimentum. Praesent at libero congue, vulputate elit ut, rhoncus erat.
",
"contentDigest": "5614c9ff7407c62db422b1da90a0e326",
"contentDigest": "f254262a22000e42becc065aab25e3a3",
"type": "MarkdownRemark",
},
"parent": "whatever",
Expand Down Expand Up @@ -152,7 +152,7 @@ Sed eu gravida mauris. Suspendisse potenti. Praesent sit amet egestas mi, sed he
Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat mattis dui nec pretium. Donec vel consectetur est. Nam sagittis, libero vitae pretium pharetra, velit est dignissim erat, at cursus quam massa vitae ligula. Suspendisse potenti. In hac habitasse platea dictumst. Donec sit amet finibus justo. Mauris ante dolor, pulvinar vitae feugiat eu, rhoncus nec diam. In ut accumsan diam, faucibus fringilla odio. Nunc id ultricies turpis. Quisque justo quam, tristique sit amet interdum quis, facilisis at mi. Fusce porttitor vel sem ut condimentum. Praesent at libero congue, vulputate elit ut, rhoncus erat.
",
"contentDigest": "5614c9ff7407c62db422b1da90a0e326",
"contentDigest": "f254262a22000e42becc065aab25e3a3",
"type": "MarkdownRemark",
},
"parent": "whatever",
Expand Down
13 changes: 4 additions & 9 deletions packages/gatsby-transformer-remark/src/on-node-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ module.exports = async function onCreateNode(
})
}

const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(data))
.digest(`hex`)
const markdownNode = {
id: `${node.id} >>> MarkdownRemark`,
children: [],
parent: node.id,
internal: {
content,
contentDigest,
type: `MarkdownRemark`,
},
}
Expand All @@ -57,10 +52,10 @@ module.exports = async function onCreateNode(

markdownNode.excerpt = data.excerpt

// Add path to the markdown file path
if (node.internal.type === `File`) {
markdownNode.fileAbsolutePath = node.absolutePath
}
markdownNode.internal.contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(markdownNode))
.digest(`hex`)

createNode(markdownNode)
createParentChildLink({ parent: node, child: markdownNode })
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/run-sift.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { trackInlineObjectsInRootNode } = require(`./node-tracking`)
const enhancedNodeCache = new Map()
const enhancedNodeCacheId = ({ node, args }) =>
node && node.internal && node.internal.contentDigest
? `${node.internal.contentDigest}${JSON.stringify(args)}`
? `${node.id}${node.internal.contentDigest}${JSON.stringify(args)}`
: null

function awaitSiftField(fields, node, k) {
Expand Down

0 comments on commit 4faec67

Please sign in to comment.