Skip to content

Commit

Permalink
fix(gatsby-transformer-json): Fix high memory consumption (#34084)
Browse files Browse the repository at this point in the history
  • Loading branch information
joernroeder authored Nov 29, 2021
1 parent e16f7f7 commit 2a94a48
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/gatsby-transformer-json/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function onCreateNode(
}
}

function transformObject(obj, id, type) {
async function transformObject(obj, id, type) {
const jsonNode = {
...obj,
id,
Expand All @@ -42,7 +42,7 @@ async function onCreateNode(
if (obj.id) {
jsonNode[`jsonId`] = obj.id
}
createNode(jsonNode)
await createNode(jsonNode)
createParentChildLink({ parent: node, child: jsonNode })
}

Expand All @@ -60,15 +60,17 @@ async function onCreateNode(
}

if (_.isArray(parsedContent)) {
parsedContent.forEach((obj, i) => {
transformObject(
for (let i = 0, l = parsedContent.length; i < l; i++) {
const obj = parsedContent[i]

await transformObject(
obj,
createNodeId(`${node.id} [${i}] >>> JSON`),
getType({ node, object: obj, isArray: true })
)
})
}
} else if (_.isPlainObject(parsedContent)) {
transformObject(
await transformObject(
parsedContent,
createNodeId(`${node.id} >>> JSON`),
getType({ node, object: parsedContent, isArray: false })
Expand Down

0 comments on commit 2a94a48

Please sign in to comment.