Skip to content

Commit 0152be0

Browse files
committed
[gatsby-source-filesystem] don't try to process same remote file multiple times, cache promises and return them on subsequent calls
1 parent 928914e commit 0152be0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/gatsby-source-filesystem/src/create-remote-file-node.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ const { isWebUri } = require(`valid-url`)
77
const { createFileNode } = require(`./create-file-node`)
88
const cacheId = url => `create-remote-file-node-${url}`
99

10-
module.exports = ({ url, store, cache, createNode, auth = {} }) =>
11-
new Promise(async (resolve, reject) => {
10+
/**
11+
* Index of promises resolving to File node from remote url
12+
*/
13+
const processingCache = {}
14+
15+
module.exports = ({ url, store, cache, createNode, auth = {} }) => {
16+
// Check if we already requested node for this remote file
17+
// and return stored promise if we did.
18+
if (processingCache[url]) {
19+
return processingCache[url]
20+
}
21+
22+
return (processingCache[url] = new Promise(async (resolve, reject) => {
1223
if (!url || isWebUri(url) === undefined) {
1324
resolve()
1425
return
@@ -99,4 +110,5 @@ module.exports = ({ url, store, cache, createNode, auth = {} }) =>
99110
resolve(fileNode)
100111
})
101112
})
102-
})
113+
}))
114+
}

0 commit comments

Comments
 (0)