mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
perf(insights): bound the medication-intake reads to the rendered window
general-status and blood-pressure-status read the full medication-intake history with no time floor, scanning every row for accounts with years of data. Both only consume the trailing ~365 days (the adherence fold and the continuity series / 7-30 day compliance gate), so add a scheduledFor floor at now - 365d. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
005f4ba2be
commit
941947399a
2 files changed
+17
-1
No files matched your search
@@ -276,6 +276,12 @@ export async function generateBloodPressureStatusForUser(
|
||||
userId,
|
||||
// v1.7.0 sync — exclude tombstoned rows.
|
||||
deletedAt: null,
|
||||
// v1.12.7 — bound to the ~365-day window the continuity series
|
||||
// and the 7/30-day compliance gate consume; this read was
|
||||
// otherwise unbounded over all intake history.
|
||||
scheduledFor: {
|
||||
gte: new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000),
|
||||
},
|
||||
medicationId: {
|
||||
in: bpMedications.map((medication) => medication.id),
|
||||
},
|
||||
|
||||
@@ -178,9 +178,19 @@ export async function generateGeneralStatusForUser(
|
||||
}),
|
||||
);
|
||||
|
||||
// v1.12.7 — bound the intake read to the ~365-day window the adherence
|
||||
// series renders. Without a `scheduledFor` floor this scanned all intake
|
||||
// history; the adherence fold below only consumes the trailing year.
|
||||
const intakeWindowStart = new Date(
|
||||
now.getTime() - 365 * 24 * 60 * 60 * 1000,
|
||||
);
|
||||
const intakeEvents = await prisma.medicationIntakeEvent.findMany({
|
||||
// v1.7.0 sync — exclude tombstoned rows.
|
||||
where: { userId, deletedAt: null },
|
||||
where: {
|
||||
userId,
|
||||
deletedAt: null,
|
||||
scheduledFor: { gte: intakeWindowStart },
|
||||
},
|
||||
orderBy: { scheduledFor: "asc" },
|
||||
select: {
|
||||
scheduledFor: true,
|
||||
|
||||
Reference in new issue
Block a user