Problem
In loans.service.ts (lines 376-378), getStats() does select * from loans with no LIMIT clause. On a production database with millions of loans, this query will crash with OOM or timeout.
User impact: At scale, the protocol stats endpoint will crash the database.
Root Cause
No pagination was added to the stats query during development.
What To Build
- Add a LIMIT clause to the stats query (e.g., LIMIT 10000 for recent loans)
- Aggregate stats using SQL aggregation (COUNT, SUM, AVG) instead of loading all rows
- Cache the result with a 5-minute TTL
Files To Touch
src/modules/loans/loans.service.ts — lines 376-378 add limit and aggregation
Acceptance Criteria
Mandatory Checks
Problem
In
loans.service.ts(lines 376-378),getStats()doesselect * from loanswith no LIMIT clause. On a production database with millions of loans, this query will crash with OOM or timeout.User impact: At scale, the protocol stats endpoint will crash the database.
Root Cause
No pagination was added to the stats query during development.
What To Build
Files To Touch
src/modules/loans/loans.service.ts— lines 376-378 add limit and aggregationAcceptance Criteria
Mandatory Checks