Skip to content

perf(metadata): cache provider searches and deduplicate requests - #2615

Open
magrhino wants to merge 1 commit into
vavallee:mainfrom
magrhino:codex/implement-caching-and-deduplication
Open

magrhino wants to merge 1 commit into
vavallee:mainfrom
magrhino:codex/implement-caching-and-deduplication

Conversation

@magrhino

Copy link
Copy Markdown
Contributor

Summary

Repeated searches and concurrent metadata cache misses currently send redundant provider requests, while routed and explicit Hardcover edition lookups can miss each other's cache entries. This change reuses successful provider responses and combines identical in-flight fetches while preserving account isolation, cancellation, complete editions, and retryable failures. Closes #2594; refs #2592.

  • Add a bounded five-minute provider search cache (1,000 entries), with keys scoped to the provider, exact query and resolved configuration.
  • Share identical in-flight metadata fetches, deep-copy returned results, and cancel upstream work when its last caller leaves. Hardcover queue admission respects the remaining callers' scheduling deadlines.
  • Resolve providers before canonicalizing edition keys; freeze live Hardcover credentials across pagination and scope raw/derived metadata caches to their inputs and provider configuration.
  • Retain the existing 24-hour in-memory metadata cache and explicit uncached provider paths. Persisted edition reuse is deferred because local rows lack a complete-snapshot freshness marker.
  • Document cache behavior and add focused coverage for bounds, expiry, concurrency, cancellation, errors, account changes, result ownership, edition identity and throttle admission.

Scope

When integrating #2593, retain quota state in token-bound clients, keep cache hits and shared waiters outside attempt accounting, and verify quota headroom for mixed interactive/background callers. This PR does not implement quota accounting.

Checklist

  • Commits signed off with git commit -s
  • Tests added or updated
  • README.md and docs/DEPLOYMENT.md updated; provider cache contract documented in CONTRIBUTING.md and godoc
  • Added changelog.d/2594-metadata-request-caching.md
  • template.env updated — N/A: no environment variables or configuration format changes
  • CHANGELOG.md updated — N/A: repository policy uses fragments and assembles the changelog at release time
  • Wiki pages updated — N/A: no series/UI workflow changes; cache behavior is documented in the deployment guide

Test plan

Go checks used GOTOOLCHAIN=go1.26.1.

  • make test — full backend tests and coverage
  • go test -race ./internal/metadata/...
  • go test -race -count=10 ./internal/metadata ./internal/metadata/hardcover
  • go vet ./...
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 run --timeout=5m ./internal/metadata/... — zero issues
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 run --timeout=5m — full Go lint, zero issues
  • git diff --check and formatting checks
  • GOTOOLCHAIN=go1.26.6 go run golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 ./... — zero affected vulnerabilities; one required-module advisory with no called vulnerable symbols
  • The same pinned vulnerability scan with GOTOOLCHAIN=go1.26.1 failed with 16 standard-library advisories. The patched-toolchain scan above passed; no repository toolchain/dependency changes are included.
  • tests/run-all.sh — N/A: backend validation uses the repository's Make targets
  • Frontend build/tests — N/A: no frontend changes
  • Docker or Compose validation — N/A: no container changes

The complete local patch passed an independent high-risk review after the cache-scope and scheduling-deadline fixes. Remote CI is not certified by these local results.

Signed-off-by: magrhino <12738722+magrhino@users.noreply.github.com>
@github-actions github-actions Bot added the bindery-notified Discord notification already sent for this PR label Sep 14, 2026
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bindery-notified Discord notification already sent for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caching and request deduplication

1 participant