Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit c06ad62

Browse files
committed
fix(pkglock): improve perf a bit by using cacache memoization
1 parent 86d5a9c commit c06ad62

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/pkglock.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ async function read ({ cache, hash, pkg, resolvedPath, isFile }) {
172172
throw new Error('read() requires a fully-resolved pkgmap file address')
173173
}
174174
try {
175-
return ccGet.byDigest(cache, hash)
175+
return ccGet.byDigest(cache, hash, { memoize: true })
176176
} catch (err) {
177177
const newResolved = await fetchPackage(cache, pkg, hash)
178178
cache = newResolved.cache
179179
hash = newResolved.hash
180180
pkg = newResolved.pkg
181-
return ccGet.byDigest(cache, hash)
181+
return ccGet.byDigest(cache, hash, { memoize: true })
182182
}
183183
}
184184

@@ -188,13 +188,13 @@ function readSync ({ cache, hash, pkg, resolvedPath, isFile }) {
188188
throw new Error('readSync() requires a fully-resolved pkgmap file address')
189189
}
190190
try {
191-
return ccGet.sync.byDigest(cache, hash)
191+
return ccGet.sync.byDigest(cache, hash, { memoize: true })
192192
} catch (err) {
193193
const newResolved = fetchPackageSync(cache, pkg, hash)
194194
cache = newResolved.cache
195195
hash = newResolved.hash
196196
pkg = newResolved.pkg
197-
return ccGet.sync.byDigest(cache, hash)
197+
return ccGet.sync.byDigest(cache, hash, { memoize: true })
198198
}
199199
}
200200

@@ -256,10 +256,10 @@ function statSync ({ cache, hash, pkg, resolvedPath, isDir }, verify) {
256256
}
257257
let info
258258
try {
259-
info = ccGet.hasContent.sync(cache, hash)
259+
info = ccGet.hasContent.sync(cache, hash, { memoize: true })
260260
} catch (err) {
261261
fetchPackageSync(cache, pkg, hash)
262-
info = ccGet.hasContent.sync(cache, hash)
262+
info = ccGet.hasContent.sync(cache, hash, { memoize: true })
263263
}
264264
if (!info) {
265265
return false
@@ -289,7 +289,7 @@ function statSync ({ cache, hash, pkg, resolvedPath, isDir }, verify) {
289289
}
290290

291291
function getPkg (cache, spec, scope, pkgName) {
292-
const { metadata } = ccGet.sync(cache, depKey(spec, scope.dependencies[pkgName]))
292+
const { metadata } = ccGet.sync(cache, depKey(spec, scope.dependencies[pkgName]), { memoize: true })
293293
return JSON.parse(metadata)
294294
}
295295

0 commit comments

Comments
 (0)