Loading
refactor(npm): unify dist-tags and packument inline-build singleflight
Summary
Follow-up to !625 (merged) (surfaced in that review): the dist-tags
(internal/format/npm/disttags.go) and packument
(internal/format/npm/packument_get.go) GET handlers carried diverged copies of
the cache-miss inline-build singleflight. This unifies them behind one shared
implementation so they cannot drift again.
Changes
- New
internal/format/npm/inline_build.go:collapseInlineBuild[R]— the sharedsingleflight.Dowrapper: owns thecontext.WithoutCancel+inlineBuildTimeoutdetach, the shared-result assertion, and the collapse-counter increment.inlineBuildKey(ns, pkg, kind)— one collapse key (replaces dist-tags' 2-arginlineBuildKeyand packument'ssingleflightKey);kindis now a parameter so kind=0/1/2 never collapse onto each other.inlineBuildTimeout— one shared 30s bound (was two identical consts).
- packument now captures
singleflight'ssharedbool and increments a newpackument_inline_build_collapsed_totalcounter (twin of dist-tags'), registered inRegisterMetrics— a stalled packument collapse rate is now alertable, not silent. - Both builds already detached the leader context; the detach now lives only in the shared helper.
Behaviour-preserving for responses; the only new output is the packument collapse metric.
Testing
go build ./...,go vet(default and-tags integration)- golangci-lint 2.12 — 0 issues
- npm unit suite with
-race; scopedDistTags|Packumentintegration tests - Added: packument collapse-metering (+N) assertion, a solo-build negative, and
a kind-distinctness case on
inlineBuildKey
Related to #217 (closed)