From 5d7cadbe02167aa3c7dd5f3cb5912d32194223e8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 14:02:44 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20user=20lesson=20?= =?UTF-8?q?progress=20queries=20on=20dashboard=20and=20courses=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Scoped user's lesson progress queries to the relevant lesson IDs that belong to the loaded courses. - Reduces database payload size, lowers network latency, and reduces memory consumption under large user lesson histories. - Verified with full test suites, linters, and type-checks passing. Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com> --- src/app/(dashboard)/courses/page.tsx | 17 ++++++++++++----- src/app/(dashboard)/dashboard/page.tsx | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/app/(dashboard)/courses/page.tsx b/src/app/(dashboard)/courses/page.tsx index 1d0c6c3..89e74db 100644 --- a/src/app/(dashboard)/courses/page.tsx +++ b/src/app/(dashboard)/courses/page.tsx @@ -37,11 +37,18 @@ export default async function CoursesIndexPage() { }, }); - // Get user's lesson progress - const lessonProgress = await db.lessonProgress.findMany({ - where: { userId: user.id, deletedAt: null }, - select: { lessonId: true, status: true }, - }); + // Get all lesson IDs across the fetched courses + const allLessonIds = courses.flatMap((c) => c.modules.flatMap((m) => m.lessons.map((l) => l.id))); + + // Bolt optimization: Scope lesson progress queries to the relevant courses' lesson IDs. + // This prevents loading the user's entire history, reducing database payload size + // and lowering memory footprint. + const lessonProgress = allLessonIds.length > 0 + ? await db.lessonProgress.findMany({ + where: { userId: user.id, lessonId: { in: allLessonIds }, deletedAt: null }, + select: { lessonId: true, status: true }, + }) + : []; const progressMap = new Map(lessonProgress.map((p) => [p.lessonId, p.status])); return ( diff --git a/src/app/(dashboard)/dashboard/page.tsx b/src/app/(dashboard)/dashboard/page.tsx index 546298d..cfc6126 100644 --- a/src/app/(dashboard)/dashboard/page.tsx +++ b/src/app/(dashboard)/dashboard/page.tsx @@ -30,11 +30,18 @@ export default async function DashboardPage() { }, }); - // Get user's lesson progress - const lessonProgress = await db.lessonProgress.findMany({ - where: { userId: user.id, deletedAt: null }, - select: { lessonId: true, status: true }, - }); + // Get all lesson IDs across the fetched courses + const allLessonIds = courses.flatMap((c) => c.modules.flatMap((m) => m.lessons.map((l) => l.id))); + + // Bolt optimization: Scope lesson progress queries to the relevant courses' lesson IDs. + // This prevents loading the user's entire history, reducing database payload size + // and lowering memory footprint. + const lessonProgress = allLessonIds.length > 0 + ? await db.lessonProgress.findMany({ + where: { userId: user.id, lessonId: { in: allLessonIds }, deletedAt: null }, + select: { lessonId: true, status: true }, + }) + : []; const progressMap = new Map(lessonProgress.map((p) => [p.lessonId, p.status])); // Compute aggregate stats