Skip to content

Commit 6f84e7e

Browse files
authored
test(cache-resilience): adjust for v4/lmdb (#33235)
1 parent f41101c commit 6f84e7e

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

integration-tests/cache-resilience/gatsby-node.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const v8 = require(`v8`)
33
const glob = require(`glob`)
44
const path = require(`path`)
55
const _ = require(`lodash`)
6+
const { open } = require(`lmdb-store`)
67

78
const { saveState } = require(`gatsby/dist/redux/save-state`)
89

@@ -16,17 +17,30 @@ const getDiskCacheSnapshot = () => {
1617
const plugins = getAllPlugins()
1718

1819
const snapshot = {}
19-
plugins.forEach(pluginName => {
20-
const cacheDirectory = path.join(__dirname, `.cache`, `caches`, pluginName)
20+
let store
21+
try {
22+
store = open({
23+
name: `root`,
24+
path: path.join(process.cwd(), `.cache/caches-lmdb`),
25+
compression: true,
26+
maxDbs: 200,
27+
})
28+
plugins.forEach(pluginName => {
29+
const pluginDb = store.openDB({
30+
name: pluginName,
31+
encoding: `json`,
32+
})
2133

22-
const files = glob.sync(path.join(cacheDirectory, `**`), {
23-
nodir: true,
34+
snapshot[pluginName] = Array.from(pluginDb.getKeys({ snapshot: false }))
2435
})
36+
} catch (e) {
37+
console.error(e)
38+
} finally {
39+
if (store) {
40+
store.close()
41+
}
42+
}
2543

26-
snapshot[pluginName] = files.map(absolutePath =>
27-
path.relative(cacheDirectory, absolutePath)
28-
)
29-
})
3044
return snapshot
3145
}
3246

0 commit comments

Comments
 (0)