perf(series): read a dense window's rows once for buckets and figures

A long-window read of a dense series sent two statements over the same
canonical rows, the day or hour buckets and the strip's figures, so a
ten-year pulse read picked the canonical source per day and scanned the
readings twice. Both aggregates now run in one statement over the window
materialised once, with the same SQL each had (dense-series-read.ts).

An integration test keeps the two old statements as the reference and
requires the same buckets and figures for pulse (two ranked sources),
glucose and oxygen saturation, day and hour grains, in UTC,
Europe/Berlin, Asia/Kolkata and America/New_York, and the same empty
answer for a type without readings.
This commit is contained in:
Marc-André Bombeck committed 2026-10-22 09:09:42 +02:00
1 parent a57fa8335a
commit f50b6b6637
5 files changed
+458 -135

No files matched your search

@@ -93,7 +93,6 @@ const HELPER: Entry = { helper: true };
/** Files with a database mean over values. */
const SQL_READERS: Record<string, Entry> = {
"app/api/measurements/series/route.ts": HELPER,
"lib/ai/coach/tools/availability.ts": HELPER,
"lib/analytics/summaries-slice.ts": HELPER,
"lib/doctor-report/dense-buckets.ts": HELPER,
@@ -102,6 +101,8 @@ const SQL_READERS: Record<string, Entry> = {
// The dry run's hour means, weighed by both methods through the helper.
"lib/jobs/pulse-day-mean.ts": HELPER,
"lib/measurements/daily-series-read.ts": HELPER,
// The series route's long-window dense read.
"lib/measurements/dense-series-read.ts": HELPER,
"lib/rollups/measurement-rollups.ts": HELPER,
"lib/rollups/tiered-context.ts": HELPER,
"lib/insights/correlation-channel-series.ts": {