Skip to content

Commit

Permalink
fix: isolate full and corgi packuments in packumentCache
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed May 7, 2024
1 parent 8b58a32 commit 7690c88
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const fullDoc = 'application/json'
const MISSING_TIME_CUTOFF = '2015-01-01T00:00:00.000Z'

class RegistryFetcher extends Fetcher {
#cacheKey
constructor (spec, opts) {
super(spec, opts)

Expand All @@ -32,8 +33,8 @@ class RegistryFetcher extends Fetcher {
this.packumentCache = this.opts.packumentCache || null

this.registry = fetch.pickRegistry(spec, opts)
this.packumentUrl = removeTrailingSlashes(this.registry) + '/' +
this.spec.escapedName
this.packumentUrl = `${removeTrailingSlashes(this.registry)}/${this.spec.escapedName}`
this.#cacheKey = `${this.fullMetadata ? 'full' : 'corgi'}:${this.packumentUrl}`

const parsed = new URL(this.registry)
const regKey = `//${parsed.host}${parsed.pathname}`
Expand Down Expand Up @@ -78,8 +79,8 @@ class RegistryFetcher extends Fetcher {
// note this might be either an in-flight promise for a request,
// or the actual packument, but we never want to make more than
// one request at a time for the same thing regardless.
if (this.packumentCache?.has(this.packumentUrl)) {
return this.packumentCache.get(this.packumentUrl)
if (this.packumentCache?.has(this.#cacheKey)) {
return this.packumentCache.get(this.#cacheKey)
}

// npm-registry-fetch the packument
Expand All @@ -99,10 +100,10 @@ class RegistryFetcher extends Fetcher {
if (contentLength) {
packument._contentLength = Number(contentLength)
}
this.packumentCache?.set(this.packumentUrl, packument)
this.packumentCache?.set(this.#cacheKey, packument)
return packument
} catch (err) {
this.packumentCache?.delete(this.packumentUrl)
this.packumentCache?.delete(this.#cacheKey)
if (err.code !== 'E404' || this.fullMetadata) {
throw err
}
Expand Down

0 comments on commit 7690c88

Please sign in to comment.