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

Commit

Permalink
fix(pkglock): improve perf a bit by using cacache memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 6, 2018
1 parent 86d5a9c commit c06ad62
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand All @@ -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 })
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit c06ad62

Please sign in to comment.