fix: cache PyPI metadata for filtered versions - #258
Merged
andrew merged 1 commit intoAug 15, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the PyPI download cooldown filtering path to reuse the existing metadata cache, preventing repeated upstream requests to the PyPI JSON metadata endpoint when multiple downloads of the same package occur within the metadata TTL.
Changes:
- Route
PyPIHandler.fetchFilteredVersionsthroughProxy.FetchOrCacheMetadatausing the same"pypi"cache namespace/key (name+"/json") as the JSON handler. - Replace streaming decode with
json.Unmarshalof the cached/fetched byte slice returned byFetchOrCacheMetadata. - Add a regression test verifying that two downloads only trigger a single upstream metadata JSON request when metadata caching is enabled.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/handler/pypi.go | Switch cooldown filtering metadata fetch to FetchOrCacheMetadata to reuse the existing PyPI JSON metadata cache entry. |
| internal/handler/pypi_test.go | Add regression test ensuring repeated downloads reuse cached PyPI JSON metadata (single upstream metadata request). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
andrew
approved these changes
Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Route
fetchFilteredVersionsinPyPIHandler.handleDownloadthrough the existingFetchOrCacheMetadatahelper instead of issuing a direct upstream request for the PyPI JSON metadata on every download.This reuses the same cache entry (
"pypi"namespace, keyname+"/json") as the existinghandleJSONpath, so repeated downloads of the same package no longer fetch the JSON metadata from upstream more than once within the metadata TTL.Why
Repeated file downloads currently trigger repeated upstream JSON metadata requests even though the project already has a metadata caching path. The npm side of the same cooldown feature already routes through
FetchOrCacheMetadata; the PyPI side was the only one left on the direct-request path.Testing
TestPyPIDownloadCooldownMetadataCache) that performs two downloads of the same package (one served, one withheld by cooldown) against anhttptestupstream and counts requests to the metadata JSON endpoint:go test ./internal/handler/— passgo test ./...— all packages passgofmtclean,go vetcleanCloses #242