Skip to content

fix: cache PyPI metadata for filtered versions - #258

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
joyheroes:fix/242-cache-pypi-filtered-versions
Aug 15, 2026
Merged

fix: cache PyPI metadata for filtered versions#258
andrew merged 1 commit into
git-pkgs:mainfrom
joyheroes:fix/242-cache-pypi-filtered-versions

Conversation

@joyheroes

Copy link
Copy Markdown
Contributor

What

Route fetchFilteredVersions in PyPIHandler.handleDownload through the existing FetchOrCacheMetadata helper instead of issuing a direct upstream request for the PyPI JSON metadata on every download.

This reuses the same cache entry ("pypi" namespace, key name+"/json") as the existing handleJSON path, 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

  • Added a regression test (TestPyPIDownloadCooldownMetadataCache) that performs two downloads of the same package (one served, one withheld by cooldown) against an httptest upstream and counts requests to the metadata JSON endpoint:
    • before fix: two upstream metadata requests
    • after fix: one upstream metadata request
  • go test ./internal/handler/ — pass
  • go test ./... — all packages pass
  • gofmt clean, go vet clean

Closes #242

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.fetchFilteredVersions through Proxy.FetchOrCacheMetadata using the same "pypi" cache namespace/key (name+"/json") as the JSON handler.
  • Replace streaming decode with json.Unmarshal of the cached/fetched byte slice returned by FetchOrCacheMetadata.
  • 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
andrew merged commit 78b29e5 into git-pkgs:main Aug 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pypi: cooldown download check makes an uncached upstream request per file

3 participants