mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
perf(dashboard): cache today's cycle read and run the vitals reads together
The digest is polled every 120 seconds. Its cycle line read the whole cycle history, 90 days of day logs and wrist temperature on every poll, outside any cache, and the coincident-deviation engine walked its eleven vitals one after another, two queries each. The cycle read now rides the digest extras cell, which every cycle write already hard-evicts; the cycle preferences route evicts it too, and a module switch does through the health-score invalidator. A record without a cycle profile stops after one point read. The per-vital reads run together and are folded in registry order, so the result does not depend on which finished first. On a seeded four-year account (1.25M measurements, 52 cycles) under a 792 MB heap, the warm digest went from 9.9 to 5.0 ms and the vitals engine from 11.1 to 4.6 ms (medians of four interleaved rounds).
This commit is contained in:
1 parent
bfcf71b7eb
commit
4bb03600b3
5 files changed
+81
-38
No files matched your search
@@ -28,6 +28,7 @@ import { prisma } from "@/lib/db";
|
||||
import { checkRateLimit, rateLimitHeaders } from "@/lib/rate-limit";
|
||||
import { getOrCreateCycleProfile } from "@/lib/cycle/profile";
|
||||
import { isCycleEnabled } from "@/lib/cycle/gate";
|
||||
import { invalidateUserHealthContext } from "@/lib/cache/invalidate";
|
||||
import { toCycleProfileDTO } from "@/lib/cycle/dto";
|
||||
import { cyclePrefsSchema } from "@/lib/validations/cycle";
|
||||
|
||||
@@ -118,6 +119,9 @@ export const PATCH = apiHandler(async (req: Request) => {
|
||||
});
|
||||
|
||||
const resolved = isCycleEnabled(user.gender, updated);
|
||||
// The typical lengths, the prediction switch and tracking itself all feed
|
||||
// the dashboard's cycle line, which is cached in the digest extras cell.
|
||||
invalidateUserHealthContext(user.id);
|
||||
|
||||
await auditLog("user.cycle-prefs.update", {
|
||||
userId: user.id,
|
||||
|
||||
Reference in new issue
Block a user