feat(analytics): replace health score with reference composite

This commit is contained in:
Marc-André Bombeck committed 2026-07-28 21:10:15 +02:00
1 parent 666a85d311
commit c91558f18f
87 files changed
+6033 -5868

No files matched your search

+31
View File
@@ -11,6 +11,7 @@ import {
invalidateUserDashboardWidgets,
invalidateUserDashboardSnapshot,
invalidateUserInsights,
invalidateUserHealthScore,
invalidateUserMeasurements,
invalidateUserMedications,
invalidateUserMood,
@@ -110,6 +111,36 @@ function snapshotCell(userId: string, locale = "en"): string {
return `${dashboardSnapshotCacheKey(userId)}|${locale}`;
}
describe("invalidateUserHealthScore", () => {
it("evicts analytics, dashboard snapshots, and derived batches for one user", async () => {
await cached(caches.analytics, `${USER_A}|default|en`, async () => ({}));
await cached(caches.analytics, snapshotCell(USER_A), async () => ({}));
await cached(
caches.insightsDerived,
`${USER_A}|batch|HEALTH_SCORE|en`,
async () => ({}),
);
await cached(caches.analytics, `${USER_B}|default|en`, async () => ({}));
await cached(
caches.insightsDerived,
`${USER_B}|batch|HEALTH_SCORE|en`,
async () => ({}),
);
invalidateUserHealthScore(USER_A);
expect(caches.analytics.get(`${USER_A}|default|en`)).toBeNull();
expect(caches.analytics.get(snapshotCell(USER_A))).toBeNull();
expect(
caches.insightsDerived.get(`${USER_A}|batch|HEALTH_SCORE|en`),
).toBeNull();
expect(caches.analytics.get(`${USER_B}|default|en`)).not.toBeNull();
expect(
caches.insightsDerived.get(`${USER_B}|batch|HEALTH_SCORE|en`),
).not.toBeNull();
});
});
describe("invalidateUserMeasurements", () => {
it("evicts analytics + achievements + workouts for the target user only", async () => {
await primeAllCaches();
+10
View File
@@ -185,6 +185,16 @@ export function invalidateUserMedications(
caches.insightsTargets.deleteByPrefix(userId);
}
/**
* Hard-evict every server cache that can carry the derived Health Score.
* Lab, assessment and score-notice mutations call this one bundle so the
* analytics report, dashboard snapshot and derived batch cannot disagree.
*/
export function invalidateUserHealthScore(userId: string): void {
caches.analytics.deleteByPrefix(`${userId}|`);
caches.insightsDerived.deleteByPrefix(`${userId}|`);
}
/**
* v1.16.8 — invalidate every cache whose payload derives from the user's
* PROFILE-level settings rather than from measurement / mood / medication