⚡ Bolt: implement request-level memoization using React cache#41
⚡ Bolt: implement request-level memoization using React cache#41RAbuseedo wants to merge 1 commit into
Conversation
Deduplicate database queries and CPU-intensive JWT verification within a single request lifecycle using React's `cache` function. This prevents redundant operations when multiple Server Components access the same session or entity data. Co-authored-by: RAbuseedo <97478862+RAbuseedo@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Implemented React
cache()for core authentication and database fetching functions:verifyTokeninlib/auth/session.tsgetUser,getUserWithTeam, andgetTeamForUserinlib/db/queries.ts🎯 Why:
In Next.js App Router, multiple Server Components and the Layout often need access to the current user or team data. Without memoization, each call to these functions would trigger a new database query or JWT verification, even within the same request.
📊 Impact:
jwtVerify, which is an expensive cryptographic operation.getUser()without needing to pass user data down as props (avoiding prop drilling) while still being performance-efficient.🔬 Measurement:
Deduplication can be verified by adding logs to the cached functions and observing that they only fire once during a page render that accesses them multiple times (e.g., the dashboard page which calls
getUserandgetTeamForUser). Verified type safety withpnpm exec tsc --noEmit.PR created automatically by Jules for task 9608255757870531926 started by @RAbuseedo