Skip to content

Eager loading - #1106

Open
OluRemiFour wants to merge 4 commits into
rinafcode:mainfrom
OluRemiFour:eager-loading
Open

Eager loading#1106
OluRemiFour wants to merge 4 commits into
rinafcode:mainfrom
OluRemiFour:eager-loading

Conversation

@OluRemiFour

Copy link
Copy Markdown
Contributor

Close: #1012
All done. Here's a summary of the changes across the two files:
src/dashboard/dashboard.service.ts:83-109
Replaced the eager find({ relations: ['enrollments'] }) with a query builder that:

  • LEFT JOINs enrollment on course
  • SELECTs course fields + COUNT(enrollment.id) as enrollmentCount
  • GROUP BYs course columns
  • ORDER BY count descending
  • LIMIT 20 via .take(20)
  • Returns raw rows (no entity hydration), mapped to the same shape as before
    src/dashboard/dashboard.service.spec.ts
  • Updated the Course mock in the shared beforeEach to include createQueryBuilder (needed by exportToCsv → getOverview → getCoursePerformanceMetrics)
  • Added a new test 'should compute course performance using aggregate query without hydrating enrollments' that asserts:
  • createQueryBuilder('course') is called (not find)
  • leftJoin('course.enrollments', 'enrollment') is used
  • addSelect('COUNT(enrollment.id)', 'enrollmentCount') is used
  • .take(20) limits the result
  • orderBy sorts descending by count
  • Results are in correct descending order with parsed numeric values
    Index verification
    enrollment.courseId already has a single-column @Index() plus two composite indexes (['courseId', 'status'], ['courseId', 'enrolledAt']). No additional index is needed.

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@OluRemiFour Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@OluRemiFour

Copy link
Copy Markdown
Contributor Author

Done, Close: #1106

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass

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.

Aggregate course enrollment counts in SQL instead of eager-loading every enrollment in the dashboard

2 participants