arch audit phase 2: reliability and perf fixes
Created by: jedmund
Summary
Phase 2 of the architecture audit — three self-contained reliability/perf fixes.
-
A-5 · Add
@@index([status, postType])onPostand@@index([isPhotography])onMedia. Covers the filter combos used by/api/postslist (status + type) and theisPhotographyfilter on Media. Migration20260420000000_add_composite_indexesincluded — runprisma migrate deployto apply. -
A-8 · New
src/lib/server/env.tsvalidatesADMIN_SESSION_SECRET,ADMIN_PASSWORD,REDIS_URL,DATABASE_URLat import time. Boot fails fast in prod if any are missing; dev warns onADMIN_PASSWORD/REDIS_URLand falls back. Wired intohooks.server.ts,admin/session.ts, andredis-client.ts. -
A-11 · Replace
include: { tags: { include: { tag: … } } }with nestedselectin/api/posts,/api/posts/[id], and/api/universe. Skips the 4 unusedPostTagjoin-row columns; detail endpoint also narrows Tag fields to{id, name, displayName, slug}(no consumer readsdescription/createdAt/updatedAt).
A-13 (script Prisma leaks) was audited — every script using Prisma already calls $disconnect() in a finally. No code change needed.
Test plan
-
pnpm check— baseline 116 errors / 9 warnings, no new ones introduced -
pnpm exec prisma migrate deployapplies the new indexes -
Boot with ADMIN_SESSION_SECRETunset → process exits with "Missing required environment variables" -
Posts list and detail responses still include tags: [{ tag: {...} }]shape (admin edit page depends on this) -
EXPLAINonSELECT * FROM "Post" WHERE status = 'published' AND "postType" = 'post'usesPost_status_postType_idx