Repository navigation
refactor(npm-resolver): move metadata request shapes and mirror header writes into one policy - #17066
Conversation
…r writes into one policy `metadataCachePolicy.ts` holds what pnpm v12's `metadata_cache_policy` decides: the document kind a mirror revalidates as, the conditional request and the unconditional refetch both request pipelines send, the release-age upgrade's request, the header line a fetched document is mirrored with (`mirrorWrite`, now the only writer for fetched documents), and the uncacheable gate (`mirrorMayAnswer`). `mirrorEtags`, `holdsFullMetaInAbbreviatedMirror`, `fullEtagOfAbbreviatedMirror`, and `revalidationOfHeldFullDocument` are gone. The release-age upgrade of a mirror that holds the full document now builds the same request as that mirror's revalidation, so `memoizeFetchMetadata` serves it the revalidation's 304. Before, the two requests differed only in property order, which gave them different memo keys and sent the same conditional request twice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@coderabbitai review |
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
PR Summary by QodoCentralize v11 npm metadata cache requests and mirror headers
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
Code Review by Qodo
1. Release notes combine old and new behavior
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
|
@MT00000002284271 |
… the release-age upgrade (#17071) An abbreviated mirror that holds the full document, recorded with `fullEtag` by an earlier release-age upgrade, is revalidated as that full document. When the document still lacks a complete `time` map, the upgrade then sent the same conditional request again. The cached fetch now reports the document kind it asked for, and the pick marks a packument fetched as `FullInAbbreviatedMirror` as upgrade-checked, so the upgrade sends nothing. Installs over such a mirror send one conditional request per package instead of two, as pnpm v11 does since #17066. Closes pnpm/tasks#150.
Summary
Part of pnpm/tasks#146, v11 only. This is the v11 counterpart of #17024 and #17028. It is independent of #17064, which handles the route decisions.
src/metadataCachePolicy.tsholds what pnpm v12'smetadata_cache_policydecides:documentKindOf:abbreviated,full,fullInAbbreviatedMirrorfullEtagOfAbbreviatedMirrorconditionalRequestfetchConditionallyinpickFromRegistry.tsandfetchMetadataCachedinfetchFullMetadataCached.tsunconditionalRefetchreleaseAgeUpgradeRequestrevalidationOfHeldFullDocumentand the held-tag logic inupgradeFreshMetaForReleaseAgemirrorWrite, the only writer of a fetched document's header linemirrorEtagsandholdsFullMetaInAbbreviatedMirrorat all four save sites: two inpickFromRegistry.ts, one infetchFullMetadataCached.ts, andpersistUpgradedMetamirrorMayAnswer, the uncacheable gate for pickscanServeCachedMetaOne behavior change. Take a mirror that holds the full document, from a registry without complete publish times. Its release-age upgrade sends the same conditional request as its revalidation.
memoizeFetchMetadatakeys requests byJSON.stringify(opts). The old code built the two requests with their properties in a different order, so they got different keys and v11 sent the same request twice. Both requests are now built by the policy, so the upgrade reuses the revalidation's 304. I updated the twopublishedBytests that counted the second 304, and added a changeset. v12 still sends both requests (upgraded_mirror_revalidation.rsexpects four 304s over installs two and three). That is a possible v12 follow-up.Tests.
test/metadataCachePolicy.test.tshas table tests for each decision, including that a written mirror revalidates the document it recorded. To test the tests, I mademirrorWriterecord every ETag asetagandconditionalRequestignorefullEtag. Seven existingpublishedBytests failed, apart from the new table. The full npm-resolver suite passes: 563 tests.A v11 bug this turned up. I fixed it separately in #17068. A full metadata pick ran the release-age upgrade. With a registry whose full documents have no
time, that downloaded the document again after every 304, and the full mirror lost itsetag. This PR keeps the current write inpersistUpgradedMeta(mirrorWrite(upgradedFrom, false)). After #17068 that write only ever reaches the abbreviated mirror.Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
pnpm changeset) if this PR changes any publishedpackage.
Written by an agent (Claude Code, claude-opus-5-5).
🤖 Generated with Claude Code
Summary by CodeRabbit