fn_getInformesBundle: studentRanking + opAsistBalance apply LIMIT 200 BEFORE ORDER BY - /informes shows an arbitrary 200 sorted, not the top 200
MEASURED LIVE 2026-08-22 (db-pluto-cc, prod prosrc confirmed to match db/migrations/applied/054-...:938/964/1010). DEFECT: two of the three capped sections build as 'FROM (SELECT * FROM "rankingRanked" LIMIT 200) rr' with the ORDER BY only in the outer jsonb_agg. A LIMIT one query level below its sort does not truncate the sorted set, it SAMPLES THE INPUT to it. Past 200 rows the card shows 200 arbitrary rows sorted descending - which renders plausibly, because the numbers still descend. Same shape in opAsistBalance (opAsistCombined), affecting its over/under flags. inactiveStudents is built correctly (ORDER BY inside the subquery, before LIMIT). LIVE, NOT LATENT. Pre-cap counts, only periodo in prod (a0000000-...001 '2026 Anual', isCurrent), unscoped admin call: rankingRanked 229, opAsistCombined 232, inactiveStudents 259. All three exceed 200. DB LANE (db-pluto-cc, claimed): move both unordered LIMIT 200s inside an ORDER BY'd subquery whose order matches the outer aggregate order exactly, tie-break columns included; apply + prosrc assert + row-count proof against the known 229/232. CODER LANE (coder-pluto-cc): the cap is undisclosed - student-ranking-card, op-asist-balance-card and inactive-students-card were grepped and none says a list is truncated, so a capped list is indistinguishable from a complete one. Surface it after the fn fix lands. OPEN QUESTION FOR PM/ELAZAR, not for the DB fix: ordering makes ranking/opAsist correct-but-truncated, which is defensible for a top-N report. inactiveStudents is different - it is an ACTIONABLE chase list and silently dropping 59 of 259 inactive students is an omission, not a presentation choice. Raising or paging that one is a product call. Provenance: found while re-scoping PLUTO-81, whose named surface (getStudentRanking/getOpAsistBalance/getInactiveStudents in src/db/queries.ts) turned out to be dead code with zero callers - only its return types are still referenced.
Activity
-
Already fixed and shipped 2026-08-22 (migration 116, commit 3424283); WI status was stale. Verified live 2026-09-11: both studentRanking and opAsistBalance order inside the capped subquery before LIMIT 200.