Overview
src/payments/payouts/payouts.service.ts loads all courses for an instructor, then all payments for all course IDs, then all refunds for all payment IDs — three sequential queries that load entire datasets into memory. An instructor with thousands of sales will cause OOM and slow API responses.
Specifications
Features:
- Use a single aggregation query (or at most two) to compute revenue breakdown.
- Support pagination so large result sets are streamed in pages.
Tasks:
- Replace separate
find() calls with a TypeORM QueryBuilder that joins Course → Payment → Refund and uses SUM/GROUP BY.
- Accept
page and limit parameters and apply OFFSET/LIMIT to the course list.
- Add a database index on
payments.courseId and refunds.paymentId if not already present.
- Benchmark before and after with 10k payments.
Impacted Files:
src/payments/payouts/payouts.service.ts
Acceptance Criteria
- Revenue breakdown for 10k payments returns in under 200ms.
- Memory usage during the call does not scale with dataset size.
- Results are identical to the current output (verified by unit test).
Overview
src/payments/payouts/payouts.service.tsloads all courses for an instructor, then all payments for all course IDs, then all refunds for all payment IDs — three sequential queries that load entire datasets into memory. An instructor with thousands of sales will cause OOM and slow API responses.Specifications
Features:
Tasks:
find()calls with a TypeORM QueryBuilder that joinsCourse → Payment → Refundand usesSUM/GROUP BY.pageandlimitparameters and applyOFFSET/LIMITto the course list.payments.courseIdandrefunds.paymentIdif not already present.Impacted Files:
src/payments/payouts/payouts.service.tsAcceptance Criteria