perf(package-requester): gate the upgrade-path SQLite probe on cheap checks

The migration block that copies a git-hosted tarball entry from the
legacy gitHostedStoreIndexKey to storeIndexKey(integrity, pkgId) was
calling storeIndex.has() on every fetch, including all npm-registry
packages it has no business probing — a SELECT per package, multiplied
across thousands of dependencies.

Reorder so the URL prefix check (isGitHostedPkgUrl) and the integrity
presence check run first, and the SQLite lookup only runs for
git-hosted resolutions with integrity in the lockfile. Same migration
behaviour, ~zero overhead on the hot path.

---
Written by an agent (Claude Code, claude-opus-4-7).
This commit is contained in:
Zoltan Kochan
2026-05-06 09:56:32 +02:00
parent 15f085767f
commit d65a383dec

View File

@@ -526,22 +526,22 @@ function fetchToStore (
// Once v12 forces lockfile regeneration, every store keyed by the new
// pnpm will already have the integrity-keyed entry and this lookup is
// dead code.
//
// Cheap string checks (URL prefix, integrity present) gate the SQLite
// existence lookup so we only probe storeIndex for git-hosted packages.
const tarballUrl = (opts.pkg.resolution as TarballResolution).tarball
if (
!opts.force &&
ctx.storeIndex != null &&
tarballUrl != null &&
(opts.pkg.resolution as TarballResolution).integrity &&
isGitHostedPkgUrl(tarballUrl) &&
!ctx.storeIndex.has(filesIndexFile)
) {
const tarballUrl = (opts.pkg.resolution as TarballResolution).tarball
if (
tarballUrl != null &&
isGitHostedPkgUrl(tarballUrl) &&
(opts.pkg.resolution as TarballResolution).integrity
) {
const legacyKey = gitHostedStoreIndexKey(opts.pkg.id, { built: !opts.ignoreScripts })
const legacyData = ctx.storeIndex.getRaw(legacyKey)
if (legacyData) {
ctx.storeIndex.setRawMany([{ key: filesIndexFile, buffer: legacyData }])
}
const legacyKey = gitHostedStoreIndexKey(opts.pkg.id, { built: !opts.ignoreScripts })
const legacyData = ctx.storeIndex.getRaw(legacyKey)
if (legacyData) {
ctx.storeIndex.setRawMany([{ key: filesIndexFile, buffer: legacyData }])
}
}