Skip to content

refactor: harden SQLite delegate cache and address review feedback#41

Open
fionnachan wants to merge 1 commit intomainfrom
db-improvement
Open

refactor: harden SQLite delegate cache and address review feedback#41
fionnachan wants to merge 1 commit intomainfrom
db-improvement

Conversation

@fionnachan
Copy link
Copy Markdown
Member

Follow-up to #39 with review fixes plus two bugs found during dev testing.

Routing and caching:

  • s-maxage + SWR replaces browser-only Cache-Control + force-dynamic so Vercel's edge cache actually serves range responses.
  • GET/HEAD wrapped in try/catch; surface 502/503 instead of bare 500.
  • Production throws when no blob env var is set; default URL is a dev-only fallback.
  • Stay on runtime=nodejs (Next's edge dev server stomps the explicit HEAD Content-Length, which breaks sql.js-httpvfs file-size discovery).

Public-file conflict (fix: 500s on /delegates):

  • SQLite build output moves from public/tally-data/ to data/build/ so the static asset no longer shadows the proxy route. Manifest stays in public/.

Manifest-driven config:

  • manifest.json gains schemaVersion, cacheBust, totalVotingPower.
  • Route and client read sizes/URLs from the manifest at runtime.
  • Deploy script no longer regex-rewrites constants in three sources.

Total voting power correctness:

  • delegate_list threshold lowered from 10 ARB to 1 ARB.
  • Total ships in the manifest; client reads it instead of summing the filtered SQL rows, so the figure no longer collapses when the user raises the display-side minimum-power filter.
  • RPC refresh applies a delta to the existing total instead of resumming the visible subset.
  • 5000 ARB UI floor pushed into SQL.

SQLite client hardening:

  • workerPromise resets on init rejection so callers can retry.
  • Stale tally-zero:sqlite:* localStorage keys swept on first load.
  • Always-zero lastChangeBlock field dropped.

Module split:

  • lib/delegate-cache.ts -> delegate-rank-cache.ts (gov-tracker) + delegate-data.ts (SQLite). All callers migrated.

Misc:

  • ElectionPageClient: useMemo side effect -> useState initializer.
  • avatar-map.json removed from git; build warns when missing and points at pnpm avatars:upload.
  • README "Data layer" section.
  • Playwright config + delegates smoke test, pnpm e2e script.
  • Route tests cover cache header, 502/503 paths, env-var guard.

Follow-up to #39 with review fixes plus two bugs found during dev testing.

Routing and caching:
- s-maxage + SWR replaces browser-only Cache-Control + force-dynamic so
  Vercel's edge cache actually serves range responses.
- GET/HEAD wrapped in try/catch; surface 502/503 instead of bare 500.
- Production throws when no blob env var is set; default URL is a
  dev-only fallback.
- Stay on runtime=nodejs (Next's edge dev server stomps the explicit
  HEAD Content-Length, which breaks sql.js-httpvfs file-size discovery).

Public-file conflict (fix: 500s on /delegates):
- SQLite build output moves from public/tally-data/ to data/build/ so
  the static asset no longer shadows the proxy route. Manifest stays
  in public/.

Manifest-driven config:
- manifest.json gains schemaVersion, cacheBust, totalVotingPower.
- Route and client read sizes/URLs from the manifest at runtime.
- Deploy script no longer regex-rewrites constants in three sources.

Total voting power correctness:
- delegate_list threshold lowered from 10 ARB to 1 ARB.
- Total ships in the manifest; client reads it instead of summing the
  filtered SQL rows, so the figure no longer collapses when the user
  raises the display-side minimum-power filter.
- RPC refresh applies a delta to the existing total instead of
  resumming the visible subset.
- 5000 ARB UI floor pushed into SQL.

SQLite client hardening:
- workerPromise resets on init rejection so callers can retry.
- Stale tally-zero:sqlite:* localStorage keys swept on first load.
- Always-zero lastChangeBlock field dropped.

Module split:
- lib/delegate-cache.ts -> delegate-rank-cache.ts (gov-tracker) +
  delegate-data.ts (SQLite). All callers migrated.

Misc:
- ElectionPageClient: useMemo side effect -> useState initializer.
- avatar-map.json removed from git; build warns when missing and points
  at pnpm avatars:upload.
- README "Data layer" section.
- Playwright config + delegates smoke test, pnpm e2e script.
- Route tests cover cache header, 502/503 paths, env-var guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 1, 2026

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

Project Deployment Actions Updated (UTC)
tally-zero Error Error May 1, 2026 6:04pm

Request Review

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