Skip to content

Extract portable Conda metadata transformations - #812

Open
simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:refactor/metadata-conda
Open

simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:refactor/metadata-conda

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Part of #501, the Conda step.

As in #612 for npm, the Conda metadata transformations move out of internal/handler into internal/metadata/conda:

  • NewFilter and Filter.Copy, the streaming repodata.json filter that leaves out entries in packages and packages.conda still in cooldown and writes everything else with its upstream bytes. Withheld and Until report what it left out and when the first of those leaves cooldown, which the handler uses to reuse the filtered copy's ETag.
  • ReadIndex, which maps each package file to its timestamp for download checks
  • DecodeShardIndex, ShardIndex.ShardsLayout, RewriteShardIndex and FilterShard for sharded repodata (CEP 16), with ShardMask and IsShardFile. They take and return the decompressed msgpack; the zstd framing stays in the handler.
  • Time, which reads a repodata timestamp as seconds or milliseconds, and FilenameIdentity

The package takes its inputs explicitly in Options: the cooldown policy and the time cooldown is evaluated at. It reports each package file cooldown leaves out through OnCooldownFilter, which the handler logs as before. It doesn't depend on handler.Proxy.

What stays in the handler: fetching, the metadata cache, the filtered copy's ETag, the decompressed size bound, gzip and zstd, routes and downloads. The handler's function names stay as thin wrappers, so the handler tests run unchanged against the real routes. internal/mirror still calls handler.CondaFilenameIdentity, to keep this PR off the import block #803 changes.

Shards are now checked with Evaluate at one EvaluatedAt per shard instead of IsAllowed per record, as repodata already was. The handler passes time.Now(), so results are the same unless a shard is filtered across a cooldown boundary. TestCooldownSupportedCoversHandlers also reads internal/metadata, the same change as in #804.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/conda works. imports_test.go fails on any non-standard import outside an allowlist (cooldown, purl, vers, packageurl-go, internal/packageurl, internal/jsonstream, and vmihailenco/msgpack with tagparser) and on net, net/http, log/slog or database/sql.

Benchmarks (internal/handler, main vs this branch, on a generated 23 MB repodata.json with 60,000 entries since the real-data benchmarks need CONDA_REPODATA_BENCH, test binaries run alternately, n=8, medians):

base branch
CondaFilterRepodata 76.60 ms 76.94 ms +0.4%
CondaReadRepodataIndex 75.61 ms 74.98 ms −0.8%

Bytes and allocations per op are unchanged within a few allocations.

New tests in internal/metadata/conda cover the filter with cooldown evaluated at EvaluatedAt, upstream bytes kept, entries without a name or timestamp, the callback, the withheld digest and Until, and a disabled or missing policy; the index reader; the shard index layout checks, the rewrite and its refusals; the shard filter with integer and float timestamps; and the timestamp rule and the filename parser. They were mutation-checked, as was the handler's wiring. go test ./... and golangci-lint run ./... pass.

The repodata.json cooldown filter, the publish-time index, the sharded
repodata index rewrite and shard filter, the timestamp rule and the
filename parser move from internal/handler to internal/metadata/conda,
which takes its inputs explicitly and doesn't depend on handler.Proxy.
The repodata filter still streams. Fetching, caches, ETag reuse, size
bounds and the zstd framing of shards stay in the handler, whose
function names remain as thin wrappers.

Shards are now checked with Evaluate at one EvaluatedAt per shard
instead of IsAllowed per record, as repodata already was.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a19d3c31-0ff0-4976-b519-1d07458fbf9e
Commits

Reviewing files that changed from the base of the PR and between be51120 and 36e6014.

Files selected for processing: 8

  • internal/handler/conda.go
  • internal/handler/conda_shards.go
  • internal/handler/cooldown_supported_test.go
  • internal/metadata/conda/imports_test.go
  • internal/metadata/conda/metadata.go
  • internal/metadata/conda/metadata_test.go
  • internal/metadata/conda/repodata.go
  • internal/metadata/conda/shards.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant