fix(dashboard-summary): exclude soft-deleted in sparkline and streak queries

`latestIn7d` and `streakDays` are raw SQL against `measurements`; the
`allTime` aggregate is `prisma.measurement.groupBy`. All three folded
tombstoned rows into the tile-strip's latest value, the all-time count
+ last-seen-at metadata, and the measurement-streak day count. The
`sparkBuckets` query reads from `measurement_rollups` so the writer-side
filter covers it.

Add `m."deleted_at" IS NULL` to the two raw queries and `deletedAt: null`
to the Prisma groupBy.
This commit is contained in:
Marc-André Bombeck committed 2026-05-21 11:44:00 +02:00
1 parent 8187d54969
commit 1bcaae4764
3 files changed
+244 -8

No files matched your search

+3 -1
View File
@@ -419,6 +419,7 @@ async function buildDashboardSummary(
FROM measurements m
WHERE m."user_id" = ${userId}
AND m."measured_at" >= ${sevenDaysAgo}
AND m."deleted_at" IS NULL
ORDER BY m."type", m."measured_at" DESC
`,
),
@@ -440,7 +441,7 @@ async function buildDashboardSummary(
time("allTime", () =>
prisma.measurement.groupBy({
by: ["type"],
where: { userId, type: { in: measurementTypes } },
where: { userId, type: { in: measurementTypes }, deletedAt: null },
_count: { _all: true },
_max: { measuredAt: true },
}),
@@ -485,6 +486,7 @@ async function buildDashboardSummary(
FROM measurements m
WHERE m."user_id" = ${userId}
AND m."measured_at" >= ${streakWindowStart}
AND m."deleted_at" IS NULL
`,
),
]);