Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log tarball retrieval from cache #403

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ class FetcherBase {
// private
// Note: cacache will raise a EINTEGRITY error if the integrity doesn't match
#tarballFromCache () {
return cacache.get.stream.byDigest(this.cache, this.integrity, this.opts)
const startTime = Date.now()
const stream = cacache.get.stream.byDigest(this.cache, this.integrity, this.opts)
const elapsedTime = Date.now() - startTime
// cache is good, so log it as a hit in particular since there was no fetch logged
log.http(
'cache',
`${this.spec} ${elapsedTime}ms (cache hit)`
)
return stream
}

get [_.cacheFetches] () {
Expand Down
10 changes: 9 additions & 1 deletion test/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ t.test('extract', t => {
}).extract(target + '/badcache')
.then(({ resolved, integrity }) => {
t.match(logs, [
['http',
'cache',
/file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/,
],
['warn', 'tar', 'zlib: incorrect header check'],
[
'silly',
Expand Down Expand Up @@ -298,7 +302,11 @@ t.test('extract', t => {
algorithm: 'sha512',
sri: Object,
}, 'got expected error')
t.same(logs, [
t.match(logs, [
['http',
'cache',
/file:test\/fixtures\/abbrev-1.1.1.tgz.*(cache hit)/,
],
[
'silly',
'tarball',
Expand Down
Loading