Skip to content

⚡ Bolt: scope user lesson progress database queries - #90

Open
projectamazonph wants to merge 1 commit into
mainfrom
fix/bolt-scope-lesson-progress-queries-836231224308898883
Open

⚡ Bolt: scope user lesson progress database queries#90
projectamazonph wants to merge 1 commit into
mainfrom
fix/bolt-scope-lesson-progress-queries-836231224308898883

Conversation

@projectamazonph

@projectamazonph projectamazonph commented Jul 28, 2026

Copy link
Copy Markdown
Owner

💡 What:
Scoped the db.lessonProgress.findMany database queries in the main courses list (src/app/(dashboard)/courses/page.tsx), the student dashboard (src/app/(dashboard)/dashboard/page.tsx), and the pending lessons list on the certificate page (src/app/(dashboard)/courses/[courseSlug]/certificate/page.tsx).

🎯 Why:
Previously, these pages fetched the user's entire lessonProgress history from the database, which leads to large database payloads, high memory consumption, and increased query latency as students complete more courses over time.

📊 Impact:
Significantly reduces query payload and memory usage by retrieving only the lessonProgress records matching the lessons rendered on the current page, ensuring O(N) database scaling relative to the active view rather than O(Total student progress history).

🔬 Measurement:
Run pnpm test and pnpm build to verify correctness. Verify that the query db.lessonProgress.findMany is scoped with lessonId: { in: allLessonIds } in all three modified locations.


PR created automatically by Jules for task 836231224308898883 started by @projectamazonph

Summary by CodeRabbit

  • Performance Improvements
    • Improved course, dashboard, and certificate loading by fetching lesson progress only for lessons currently displayed.
    • Reduced unnecessary data retrieval, helping decrease query latency, memory usage, and response payload sizes.
    • Added efficient handling for courses with no lessons by skipping unnecessary progress queries.

…nt lessons

Avoid fetching the student's entire lesson progress history in the courses catalog, student dashboard, and certificate pages. Restrict queries using `lessonId: { in: allLessonIds }` where `allLessonIds` matches only the lessons rendered on the specific page. This prevents redundant database records, reduces memory footprint, and improves response latency.

Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 28, 2026 13:55
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Dashboard, course index, and certificate pages now filter lessonProgress queries by the lesson IDs currently loaded for their respective views, avoiding unscoped user-history queries. The Bolt journal documents this optimization.

Changes

Lesson progress query scoping

Layer / File(s) Summary
Scope progress retrieval to loaded lessons
src/app/(dashboard)/dashboard/page.tsx, src/app/(dashboard)/courses/page.tsx, src/app/(dashboard)/courses/[courseSlug]/certificate/page.tsx, .jules/bolt.md
Dashboard, course index, and certificate pages derive relevant lesson IDs and query only matching progress records, using empty results when no lessons are present. The Bolt journal records the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: scoping lesson progress queries to relevant lessons for performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bolt-scope-lesson-progress-queries-836231224308898883

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.jules/bolt.md:
- Around line 7-9: Rewrite the journal entry’s Learning and Action text in plain
language: explain that unscoped queries load unused records, use more memory,
and can slow the page. Replace technical terms such as “payloads” and “query
latency” with direct wording while preserving the guidance to filter progress by
the relevant lessonIds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 94916e55-de82-465f-9deb-b1b6bbddcf53

📥 Commits

Reviewing files that changed from the base of the PR and between dabee94 and e16f2ae.

📒 Files selected for processing (4)
  • .jules/bolt.md
  • src/app/(dashboard)/courses/[courseSlug]/certificate/page.tsx
  • src/app/(dashboard)/courses/page.tsx
  • src/app/(dashboard)/dashboard/page.tsx

Comment thread .jules/bolt.md
Comment on lines +7 to +9
## 2026-07-17 - [Querying Unscoped User Lesson Progress History]
**Learning:** Querying a user's entire `lessonProgress` history without scoping to relevant courses or specific lesson IDs fetches redundant records from the database, resulting in unnecessary payloads, high memory consumption, and increased query latency as the student progresses.
**Action:** Extract the specific `lessonIds` of interest (e.g. from current courses/modules being rendered) and filter the progress lookup with `lessonId: { in: lessonIds }`. Avoid fetching the entire table by always scoping user-specific queries.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use plain language for the journal entry.

“Payloads” and “query latency” are unexplained jargon. State that the query loads unused records, consumes more memory, and can slow the page.

Suggested wording
-**Learning:** Querying a user's entire `lessonProgress` history without scoping to relevant courses or specific lesson IDs fetches redundant records from the database, resulting in unnecessary payloads, high memory consumption, and increased query latency as the student progresses.
-**Action:** Extract the specific `lessonIds` of interest (e.g. from current courses/modules being rendered) and filter the progress lookup with `lessonId: { in: lessonIds }`. Avoid fetching the entire table by always scoping user-specific queries.
+**Learning:** Querying a user's entire `lessonProgress` history loads records the page does not use. This uses more server memory and can make the page slower as the student completes more lessons.
+**Action:** Get the lesson IDs shown on the page and filter the progress lookup with `lessonId: { in: lessonIds }`. This loads only the progress records the page needs.

As per coding guidelines, define jargon and use direct, plain-spoken language for the Filipino VA audience.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 2026-07-17 - [Querying Unscoped User Lesson Progress History]
**Learning:** Querying a user's entire `lessonProgress` history without scoping to relevant courses or specific lesson IDs fetches redundant records from the database, resulting in unnecessary payloads, high memory consumption, and increased query latency as the student progresses.
**Action:** Extract the specific `lessonIds` of interest (e.g. from current courses/modules being rendered) and filter the progress lookup with `lessonId: { in: lessonIds }`. Avoid fetching the entire table by always scoping user-specific queries.
## 2026-07-17 - [Querying Unscoped User Lesson Progress History]
**Learning:** Querying a user's entire `lessonProgress` history loads records the page does not use. This uses more server memory and can make the page slower as the student completes more lessons.
**Action:** Get the lesson IDs shown on the page and filter the progress lookup with `lessonId: { in: lessonIds }`. This loads only the progress records the page needs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.jules/bolt.md around lines 7 - 9, Rewrite the journal entry’s Learning and
Action text in plain language: explain that unscoped queries load unused
records, use more memory, and can slow the page. Replace technical terms such as
“payloads” and “query latency” with direct wording while preserving the guidance
to filter progress by the relevant lessonIds.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants