mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(api): aggregate measurements before applying the take limit
Push range-aware aggregation into Postgres via `date_trunc` so the bucket cap applies AFTER bucketising, not before. A 1-year `aggregate=daily` request on a minute-by-minute pulse account now walks every row in the window and returns up to 365 daily buckets instead of silently truncating to the first N raw rows. Gate the aggregation branch on an explicit `aggregate` query param. Callers that pass `from`/`to` without `aggregate` (the iOS path) keep the raw `MeasurementWireDTO` wire shape — the v1.5 locked contract stays byte-stable. The new `monthly` grain bounds multi-year "All time" charts at 24 buckets per type.
This commit is contained in:
1 parent
b3f88026f0
commit
0d256230ef
5 files changed
+289
-58
No files matched your search
@@ -254,9 +254,11 @@ export const listMeasurementsSchema = z.object({
|
||||
.default("measuredAt"),
|
||||
sortDir: z.enum(["asc", "desc"]).optional().default("desc"),
|
||||
// v1.4.28 FB-D2 — bucket hint for range-aware queries. When set the
|
||||
// GET handler downsamples server-side via `aggregateRows` and returns
|
||||
// GET handler runs a server-side `date_trunc` aggregation and returns
|
||||
// one row per bucket per type rather than the raw measurement rows.
|
||||
aggregate: z.enum(["raw", "daily", "weekly"]).optional(),
|
||||
// Omitting `aggregate` keeps the raw wire shape (iOS contract); the
|
||||
// chart-data client must opt in explicitly.
|
||||
aggregate: z.enum(["raw", "daily", "weekly", "monthly"]).optional(),
|
||||
});
|
||||
|
||||
export const createBatchMeasurementSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user