mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
The W2-of-v1.4.20 BD-Zielbereich fix needed the complete sys + dia series to compute the all-time + prior-month + prior-year windows, so it pulled both tables via single-shot `findMany`. For a 5-year power user (~9 000 rows per side) that's a 50-100 ms Prisma round- trip and a ~2 MB working-set allocation per /api/analytics request. Switch to a cursor-paged 5 000-row chunked read via the new `fetchBpSeriesChunked()` helper. The accumulated `BpReading[]` is the same shape `computeBpInTargetWindows()` already consumed; the working-set ceiling is now `BP_CHUNK_SIZE` instead of unbounded. Safety bound at 1 000 pages = 5 M rows so a cursor-staleness bug can't loop forever. Wide-event annotation `analytics.bp_in_target.row_count` (+ per-side `sys_rows` / `dia_rows`) lets ops attribute slow requests to outlier users without rerunning the DB queries. Integration test seeds a 6 000-row dataset (3 000 sys + 3 000 dia) spanning a chunk boundary and asserts the response shape stays the same — last30Days, last7Days, allTime windows all carry the hand-derivable percentages. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>