Repository navigation
Admin page: clear the result cache and change federation settings live - #83
Merged
Merged
Conversation
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
…ache /admin also lists every federation setting (databases, MCP peers, patient-level federation, access) with its environment value and any override, and lets an administrator set or reset one for the whole deployment. lib/settings.ts: an app_setting row (migration 0010) overrides the environment variable of the same name for every process within seconds; federation code reads settings through setting(name), never process.env. cacheVersion() — the data version plus the settings' fingerprint, which includes the last clear — keys every cached entry, so nothing computed under old settings is served under new ones; a clear also still expires RESULT_TAG. Database addresses and credentials are never editable. Cherry-picked from the WIP commit 17cc230 (session/admin-federation) onto the cache-clearing commit; where they overlapped, the WIP version already contained the cache clearing. Requires db/migrations/0010_app_settings.sql. Unit tests (1674) pass; the gate has not been run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTXZQm7eQwpY7oWgS4D
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Supersedes #82 — this branch contains its commit (
ced27b5, clearing the result cache) plus the federation settings on top.What
A signed-in user whose email is in
ADMIN_EMAILSgets Admin in the account menu, opening/admin:How
lib/settings.ts: anapp_settingrow overrides the environment variable of the same name for every server process within seconds. Federation code reads settings throughsetting(name), neverprocess.env. Database addresses and credentials are never editable.app_setting_logrecords every change, who made it, and the value before and after (append-only for the app role).cacheVersion()(lib/next-cache.ts) — the data version plus the settings' fingerprint, which includes the last clear — is now every cached entry's key argument, so nothing computed under old settings is served under new ones. A clear also still expiresRESULT_TAG. Cohort locks keepdataVersion()alone.requireAdmin(lib/auth.ts) refuses with 404 where the deployment has no sign-in and 403 for anyone signed out or not listed.Deploy
Requires migration
db/migrations/0010_app_settings.sql— runnpm run db:migrate(withMIGRATION_DATABASE_URL) against production before deploying. Already applied to the dev Supabase database.Testing
test/settings.db-test.ts(new),test/auth.test.ts,test/result-cache-tag.test.ts🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3ezTXZQm7eQwpY7oWgS4D