fix(api): Cache-Control + Vary on /api/v1/usage/wall#190
Merged
mastermanas805 merged 2 commits intoMay 30, 2026
Conversation
be165df to
f54224d
Compare
BUG-API-420: the dashboard fetches /api/v1/usage/wall on every nav
(Overview mount + 5-min poll); without a cache hint the browser
re-fetches on every back/forward / SPA route change, generating
redundant scans on the busy team-scoped audit_log table.
Stamp `Cache-Control: private, max-age=30` + `Vary: Authorization`
on every 200 path. Consistency tradeoff (memory rule
feedback_caching_and_consistency_tradeoffs):
- worker writes ≤1 near_quota_wall row per team per 24h
(quotaWallDedupeWindow), so 30s staleness window can miss a
brand-new wall event by ≤30s — irrelevant for a soft upgrade
nudge.
- hard 402 quota enforcement still fires synchronously on the
next provision regardless of cached banner state.
- 30s << the 5-min dashboard poll interval, so walls become
visible within 5min + 30s in the worst case.
- Vary: Authorization keys per-team caching to the bearer token
so a shared CDN / browser back-cache after re-auth never
serves team A's banner to team B.
Coverage block (rule 17):
Symptom: /api/v1/usage/wall returns no Cache-Control hint
Enumeration: GetWall has THREE distinct 200 code paths
(team-tier short-circuit, no-recent-row,
row-found-with-metadata).
Sites found: 3
Sites touched: 3 — one setUsageWallCacheHeaders call on each
Coverage test: TestUsageWall_CacheHeadersOnEvery200Path iterates
the registry of 3 paths via a test table and asserts
the same Cache-Control + Vary on every one — adding
a 4th 200 path without the cache header fails the
test (rule 18 registry-iterating pattern).
Live verified: pending CI auto-deploy (rule 14 SHA check after merge).
setUsageWallCacheHeaders: 100% covered.
GetWall: 96.3% (uncovered: pre-existing db_failed branch).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…eHeaders golangci-lint flagged the constant as unused — it was kept as a single-source-of-truth comment but never read. Wire it through fmt.Sprintf so the wire value and the comment are coupled: anyone deleting the constant must also touch the format string. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f54224d to
013b0b6
Compare
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.
Summary
Consistency tradeoff (memory rule feedback_caching_and_consistency_tradeoffs)
Coverage block (rule 17)
Test plan
go build ./...cleango vet ./...cleango test ./internal/handlers -run TestUsageWallall passcurl -i -H "Authorization: Bearer <pat>" https://api.instanode.dev/api/v1/usage/wall | grep -i 'cache-control\|^vary'Inbox: BUG-API-420