mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
fix(summaries-slice): exclude soft-deleted measurements
The four `$queryRaw` blocks in `computeFromRollups` and `computeFromLiveAggregate` (narrow aggregate + DISTINCT ON latest, both fast and cold paths) folded every row regardless of `deleted_at`. The DAY-bucket rollup aggregate is unaffected because its source table is already filtered by the writer. Add `AND m."deleted_at" IS NULL` to every `FROM measurements m` WHERE clause so the slim slice's avg7/avg30/slope/r2 plus the per-type latest never reflect a row the user soft-deleted.
This commit is contained in:
1 parent
f0a0551a80
commit
1f49041025
1 file changed
+4
@@ -301,6 +301,7 @@ async function computeFromRollups(userId: string): Promise<SummariesSlice> {
|
||||
)::double precision AS r2_90
|
||||
FROM measurements m
|
||||
WHERE m."user_id" = ${userId}
|
||||
AND m."deleted_at" IS NULL
|
||||
GROUP BY m."type"
|
||||
`,
|
||||
prisma.$queryRaw<LatestRow[]>`
|
||||
@@ -310,6 +311,7 @@ async function computeFromRollups(userId: string): Promise<SummariesSlice> {
|
||||
m."measured_at" AS measured_at
|
||||
FROM measurements m
|
||||
WHERE m."user_id" = ${userId}
|
||||
AND m."deleted_at" IS NULL
|
||||
ORDER BY m."type", m."measured_at" DESC
|
||||
`,
|
||||
// v1.4.37.2 hotfix — the v1.4.35 implementation read EVERY DAY
|
||||
@@ -487,6 +489,7 @@ async function computeFromLiveAggregate(
|
||||
)::double precision AS r2_90
|
||||
FROM measurements m
|
||||
WHERE m."user_id" = ${userId}
|
||||
AND m."deleted_at" IS NULL
|
||||
GROUP BY m."type"
|
||||
`,
|
||||
prisma.$queryRaw<LatestRow[]>`
|
||||
@@ -496,6 +499,7 @@ async function computeFromLiveAggregate(
|
||||
m."measured_at" AS measured_at
|
||||
FROM measurements m
|
||||
WHERE m."user_id" = ${userId}
|
||||
AND m."deleted_at" IS NULL
|
||||
ORDER BY m."type", m."measured_at" DESC
|
||||
`,
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user