← All ideas

Other: Dedupe the session per request with React cache() and parallelize layout reads

NewOtherIdea

getCurrentUser (lib/session.ts:54-71) runs 3 times per request: in Header, in the app layout and in the page. Each call does getServerSession, getUserByEmail and resolveWorkspace (up to 4 queries), and in DEMO_MODE it also writes UPDATE users SET seeded_at. The app layout adds countDueTasks and about 12 sequential getTranslations calls. Locally TTFB is 20-40 ms, but on Turso every query is a round-trip. First scope: wrap getCurrentUser in cache(), use Promise.all in app/[locale]/app/layout.tsx, and keep the seeded flag in memory for the demo user. Priority: high. Effort: S.

Comments 0

No comments yet.