Skip to content

Warm pinned card variants or stop advertising them #5

Done

Description

@LangerSword

Current behavior

The README advertises pinned card variants with ?country= and ?team=, but those variants are never warmed. The plain card is served from R2; a pinned variant returns 404 from the empty cache path.

Live probes:

torvalds.png                 200   x-og-cache: r2-hit
torvalds.png?country=nl      404   x-og-cache: miss-empty
torvalds.png?team=ferrari    404   x-og-cache: miss-empty

Cause

app/api/card-image/[username]/route.tsx:28-33 builds the cache key from the lowercased login plus the country and team query values. app/api/cache-image/route.ts:18-19 accepts only a login and writes cardpng:v10:${login}::, with empty variant fields. components/WarmOnView.tsx:47-55 sends only kind=card&login=...; app/[username]/page.tsx:316 does not pass the current country or team.

The browser does render the correct variant on the page. The bytes simply never reach the key the image route reads.

Expected behavior

Warm the exact variant currently displayed, or stop advertising variants that cannot be cached. If the variant is supported, pass country and team through WarmOnView and cache-image, build the same key in both places, and keep the plain key for the default view.

Scope

  • components/WarmOnView.tsx
  • app/api/cache-image/route.ts
  • app/[username]/page.tsx
  • app/api/card-image/[username]/route.tsx key helper
  • a route test for default and pinned variants

Acceptance

  • A page opened with ?country=nl or ?team=ferrari warms the matching variant.
  • The variant URL returns 200 with real bytes after the warm write.
  • The plain URL keeps its own object and is not evicted by a variant.
  • Tests cover both keys and the default fallback.

Activity

  1. added
    bug
    help wanted
    on Nov 24, 2026
  2. saswatdutta1310 commented on Nov 26, 2026

    @saswatdutta1310
    Contributor

    Taking this one. Reproduced on current main: /api/cache-image writes cardpng:v10:<login>:: for every card warm, while /api/card-image/[username] reads ...:<country>:<team> for pinned variants — so the warm write lands in a key no variant request reads. Root cause is the duplicated key construction; fix is a shared normalising key helper passed through WarmOnView. PR will come from my fork.

  3. LangerSword commented on Nov 26, 2026

    @LangerSword
    OwnerAuthor

    Thanks for taking this — your read matches what I see on current main:

    • app/api/cache-image/route.ts:18 writes cardpng:v10:${login}::
    • app/api/card-image/[username]/route.tsx:30 reads cardpng:v10:${lower}:${override}:${teamCode}
    • components/WarmOnView.tsx:64-67 only sends kind=card&login=..., and app/[username]/page.tsx:316 passes nothing else

    So the warm write lands in a key no variant read can hit. Agreed that a shared key helper is the right shape.

    Two points need clarity before the PR, because they decide whether the helper actually closes the gap:

    1. Both sides must call it. If only cache-image normalises, write and read can still diverge on case — pickFlag() returns lowercase codes (nl) and pickTeam() uppercases codes (FER), while the OG route currently drops raw query strings into the key. Which value is canonical: the raw query, or the resolved flag/team? My preference is the resolved values, so ?country=NL and ?country=nl share one object and an invalid override doesn't mint a variant key holding plain bytes.

    2. Team input. The issue's probe uses ?team=ferrari, but pickTeam() only accepts codes (FER, RBR, …) and returns null for a full name. Are we fixing code-only pins, or does the parser need to accept names too? Either way an invalid override should fall back to the plain key rather than create a variant key.

    Please also cover the acceptance list in the PR: tests for the default key and both pinned keys, plus a check that warming a variant does not evict the plain object. And app/[username]/page.tsx will need to hand the current country/team to WarmOnView — if you'd rather leave the page alone, say why, because the displayed variant would still go unwarmed.

    I'll keep an eye out for the PR from your fork.

    Initial draft by me; final message written with Hermes Agent.

  4. saswatdutta1310 commented on Nov 26, 2026

    @saswatdutta1310
    Contributor

    Answering your two points before the PR (grant is still off on my side, so the branch is committed locally but not pushed yet):

    1. Canonical value = resolved values. Both routes now call the same cardCacheKey() helper, which runs normalizeCountry() and pickTeam() on both the read and write side. So ?country=NL and ?country=nl share the nl object, and an invalid override normalises to empty instead of minting a variant key. The page passes the explicit query values (sp.country / sp.team) rather than the resolved display flag or cookie prefs — the embed read path only knows the query string, so passing displayFlag would warm :nl:FER for a ?team=FER visit while that embed reads ::FER. An independent review caught exactly that gap and it is fixed in the branch.

    2. Team input stays code-only. I did not widen pickTeam() to accept full names. TeamPicker writes codes (FER, RBR, ...), so ?team=ferrari now normalises to the plain key rather than creating a variant that holds plain bytes. If you want name aliases too, that is a small follow-up in pickTeam(), but it changes the parser rather than the cache contract, so I kept it out of this fix.

    Acceptance coverage in tests/card-variant-warm.test.ts: default/plain key, pinned flag+team, raw-vs-normalised parity, team-only parity, no-query parity, and plain vs pinned remaining distinct objects. Live probe on current production still returns 404 / x-og-cache: miss-empty for /torvalds.png?country=nl&team=FER; the plain card is r2-hit. The PR body will carry the same evidence and disclosure.

  5. LangerSword commented on Nov 26, 2026

    @LangerSword
    OwnerAuthor

    Assigned @saswatdutta1310 to #5
    All the best!

  6. saswatdutta1310 commented on Nov 26, 2026

    @saswatdutta1310
    Contributor

    PR is up: #17 — from my fork, branch bot/fix-pinned-card-variant-warm-issue-5, head ca900ea. It applies the shared normalising key helper on both read and write paths, passes explicit query variants through WarmOnView, and adds the route-parity tests discussed above. Locally: 47/47 tests, tsc clean, lint 0 errors, build green. CI on the PR had not reported checks when I opened it.

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

Metadata

Metadata

Labels

bughelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions