Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/app/(dashboard)/courses/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
17 changes: 12 additions & 5 deletions src/app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down