Skip to content

Admin page: clear the result cache - #82

Closed
alisman wants to merge 1 commit into
masterfrom
session/cache
Closed

alisman wants to merge 1 commit into
masterfrom
session/cache

Conversation

@alisman

@alisman alisman commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

What

  • Admin page. Signed-in users whose email is in the new ADMIN_EMAILS env var get Admin in the account menu, which opens /admin. Its one action is Clear the cache, which empties the result cache for the whole deployment.
  • How the clear works. Every 'use cache: remote' body now starts with resultEntry() (lib/next-cache.ts), which keeps the one-day lifetime and adds the tag RESULT_TAG. POST /api/admin {action:"clearCache"} expires that tag with revalidateTag(tag, { expire: 0 }).
    • On Vercel this clears the Runtime Cache shared by every function instance.
    • Elsewhere it clears the memory of the server process that answers the request.
  • No database change. Nothing records the clear.
  • Access (requireAdmin, lib/auth.ts):
    • 404 on a deployment with no sign-in; 403 for anyone signed out or not listed.
    • With the development sign-in anyone can claim any email, so there the check is a convenience, not a guard. That sign-in is already refused on Vercel production.

Before merging

Set ADMIN_EMAILS (comma-separated) in Vercel production. Without it, nobody sees the page.

Verified

  • On an isolated next dev (in-process Postgres, dev sign-in):
    • Explore: 55 ms cached → 707 ms recomputed after a clear → 36 ms cached again. The study list behaved the same way.
    • Signed-out and non-admin requests are refused, and a non-admin has no menu item.
    • Drove the page and its confirm dialog in Chromium: no console errors.
  • New tests:
    • test/auth.test.ts covers who counts as an admin.
    • test/result-cache-tag.test.ts fails if a cached body lacks resultEntry(), which would let it survive a clear. I confirmed it fails by planting one.
  • Gate: lint, build, unit tests (1674) and postgres (66) passed. I stopped it before e2e, so e2e has not run; CI will run it.

Not in this PR

Live-editing the federation settings is on the local branch session/admin-federation (not pushed). It needs migration 0010 on Supabase, which is waiting on the owner database URL.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTZPdCcLJ4FcYtykedj

A signed-in user whose email is in ADMIN_EMAILS gets "Admin" in the account menu, opening /admin,
whose one action is clearing the result cache for the whole deployment.

Every 'use cache: remote' body now starts with resultEntry() (lib/next-cache.ts), which sets the
day's lifetime as before and tags the entry RESULT_TAG; POST /api/admin {action: "clearCache"}
expires that tag with revalidateTag(tag, {expire: 0}). On Vercel that is the Runtime Cache shared
by every function instance; elsewhere it is the answering process's own memory. No database
change: nothing records the clear.

requireAdmin (lib/auth.ts) refuses with 404 where the deployment has no sign-in and 403 for anyone
signed out or not listed. With the development sign-in anyone can claim an address, so there it is
a convenience, not a guard; that sign-in is already refused on Vercel production.

Verified on an isolated next dev (in-process Postgres, dev sign-in): Explore 55 ms cached ->
707 ms recomputed after a clear -> 36 ms cached again, the study list likewise; a signed-out and
a non-admin request are refused; a non-admin has no menu item; the page and its confirm flow
driven in Chromium with no console errors. test/auth.test.ts covers who is an admin;
test/result-cache-tag.test.ts fails on a cached body without resultEntry() (checked by planting
one). Gate: lint, build, unit (1674) and postgres (66) passed; stopped before e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTZPdCcLJ4FcYtykedj
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbiolab-genie Ready Ready Preview Oct 27, 2026 1:23pm UTC
cohort-lab Ready Ready Preview Oct 27, 2026 1:23pm UTC

Request Review

@alisman

alisman commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #83, which contains this commit plus live federation settings on /admin.

@alisman alisman closed this Oct 27, 2026
@alisman
alisman deleted the session/cache branch October 28, 2026 15:58

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — ced27b5d Deployed Oct 27, 2026 by vercel[bot]
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