From c06ad624eea0e1eb091813ef53a32d8a04953283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 5 Nov 2018 16:25:11 -0800 Subject: [PATCH] fix(pkglock): improve perf a bit by using cacache memoization --- lib/pkglock.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pkglock.js b/lib/pkglock.js index 4763e66..8bf6826 100644 --- a/lib/pkglock.js +++ b/lib/pkglock.js @@ -172,13 +172,13 @@ async function read ({ cache, hash, pkg, resolvedPath, isFile }) { throw new Error('read() requires a fully-resolved pkgmap file address') } try { - return ccGet.byDigest(cache, hash) + return ccGet.byDigest(cache, hash, { memoize: true }) } catch (err) { const newResolved = await fetchPackage(cache, pkg, hash) cache = newResolved.cache hash = newResolved.hash pkg = newResolved.pkg - return ccGet.byDigest(cache, hash) + return ccGet.byDigest(cache, hash, { memoize: true }) } } @@ -188,13 +188,13 @@ function readSync ({ cache, hash, pkg, resolvedPath, isFile }) { throw new Error('readSync() requires a fully-resolved pkgmap file address') } try { - return ccGet.sync.byDigest(cache, hash) + return ccGet.sync.byDigest(cache, hash, { memoize: true }) } catch (err) { const newResolved = fetchPackageSync(cache, pkg, hash) cache = newResolved.cache hash = newResolved.hash pkg = newResolved.pkg - return ccGet.sync.byDigest(cache, hash) + return ccGet.sync.byDigest(cache, hash, { memoize: true }) } } @@ -256,10 +256,10 @@ function statSync ({ cache, hash, pkg, resolvedPath, isDir }, verify) { } let info try { - info = ccGet.hasContent.sync(cache, hash) + info = ccGet.hasContent.sync(cache, hash, { memoize: true }) } catch (err) { fetchPackageSync(cache, pkg, hash) - info = ccGet.hasContent.sync(cache, hash) + info = ccGet.hasContent.sync(cache, hash, { memoize: true }) } if (!info) { return false @@ -289,7 +289,7 @@ function statSync ({ cache, hash, pkg, resolvedPath, isDir }, verify) { } function getPkg (cache, spec, scope, pkgName) { - const { metadata } = ccGet.sync(cache, depKey(spec, scope.dependencies[pkgName])) + const { metadata } = ccGet.sync(cache, depKey(spec, scope.dependencies[pkgName]), { memoize: true }) return JSON.parse(metadata) }