Overview
KpiService.calculateEnrollmentConversionRate() in src/utils/masking/kpi.service.ts (around lines 113-129) loads every course and then, inside a for loop, issues two queries per course (an enrollment count and a course-view getCount). With N courses this is 2N+1 round-trips every run, and the method is triggered by an EVERY_5_MINUTES cron. This N+1 pattern scales poorly as the catalog grows.
Specifications
Features:
- Enrollment-conversion metrics are computed with a bounded number of queries, independent of course count.
Tasks:
- Replace the per-course loop with grouped aggregate queries: one
GROUP BY courseId for enrollment counts and one for course-view counts, then compute the ratio in memory.
- Preserve the existing gauge labels and values.
Impacted Files:
src/utils/masking/kpi.service.ts
Acceptance Criteria
- The method issues a small constant number of queries regardless of the number of courses.
- The reported conversion rates match the previous per-course computation.
- All the CI passes
- Star the repo
Overview
KpiService.calculateEnrollmentConversionRate()insrc/utils/masking/kpi.service.ts(around lines 113-129) loads every course and then, inside aforloop, issues two queries per course (an enrollmentcountand a course-viewgetCount). With N courses this is 2N+1 round-trips every run, and the method is triggered by anEVERY_5_MINUTEScron. This N+1 pattern scales poorly as the catalog grows.Specifications
Features:
Tasks:
GROUP BY courseIdfor enrollment counts and one for course-view counts, then compute the ratio in memory.Impacted Files:
src/utils/masking/kpi.service.tsAcceptance Criteria