mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
Quality-leap release between two HealthKit milestones. The headline is a P0 hotfix for the `/api/analytics` 500 that broke the Insights mother page for any account with more than a few thousand measurements: the six per-metric status helpers were spreading the entire numeric history into `Math.min` / `Math.max`, which trips a stack overflow once a single argument list exceeds the V8 spread cap. Both the surfaced symptom and the latent risk in five sibling helpers were folded onto a reduce-based min/max path. Around that hotfix landed a deep polish pass: the Insights mother page now defers three below-the-fold blocks behind `next/dynamic` to trim the cold mount cost, the analytics endpoint gained a `?slice=summaries` slim slice that the per-metric sub-pages now ride, the Coach snapshot builder picked up a 60 s LRU keyed on `(userId, scope)`, the Settings shell consolidated three duplicate copies of the about / notifications / about-dropdown surfaces, the navigation strip dropped a redundant "Home" group label and a colliding "Notifications" sibling, every icon-only button on the medications and admin surfaces gained an accessible name, every Progress bar gained one too, three pages had their heading hierarchy repaired to a sequential h1 → h2 → h3, the mobile Coach FAB now hides while a chart tooltip is open so it cannot occlude the read-out, and the auth shell normalised every authenticated route to a single `max-w-screen-xl` container. Also lands the Apple App Site Association handler at `/.well-known/apple-app-site-association` on every host that fronts the app, advertising the iOS bundle's App ID prefix (S8WDX4W5KX.dev.healthlog.app) under `webcredentials.apps` so the passkey ceremony shares cleanly between the web origin and the iOS app. The release closes nineteen issues from a five-surface audit + a runtime bug-hunt pass, plus six follow-up tracks of polish across the affected surfaces.
166 lines
6.3 KiB
TypeScript
166 lines
6.3 KiB
TypeScript
/**
|
|
* Centralized TanStack Query key factory.
|
|
*
|
|
* Every useQuery/invalidateQueries call should go through this factory so that
|
|
* mutations invalidate the right consumers. Hard-coded string arrays drifted in
|
|
* the past (e.g. ["measurements"] didn't invalidate ["analytics"] on the
|
|
* dashboard), so treat this file as the single source of truth.
|
|
*/
|
|
|
|
import type { QueryClient, QueryKey } from "@tanstack/react-query";
|
|
|
|
export const queryKeys = {
|
|
auth: () => ["auth"] as const,
|
|
authRegistrationStatus: () => ["auth", "registration-status"] as const,
|
|
|
|
measurements: () => ["measurements"] as const,
|
|
moodEntries: () => ["mood-entries"] as const,
|
|
|
|
/**
|
|
* v1.4.33 IW2 — the analytics queryKey now optionally carries a
|
|
* `slice` discriminator so the dashboard tile-strip can subscribe to
|
|
* the slim `?slice=summaries` server slice (IW1 / C1) without
|
|
* colliding with the thick-payload consumers on the Insights tree.
|
|
* Calling `queryKeys.analytics()` without a slice keeps the legacy
|
|
* shape `["analytics"]` so mutation invalidations and the bulk-key
|
|
* lists below stay byte-identical.
|
|
*/
|
|
analytics: (slice?: "summaries") =>
|
|
(slice ? (["analytics", slice] as const) : (["analytics"] as const)),
|
|
moodAnalytics: () => ["mood-analytics"] as const,
|
|
|
|
insightsRoot: () => ["insights"] as const,
|
|
insightsComprehensive: () => ["insights", "comprehensive"] as const,
|
|
insightsTargets: () => ["insights", "targets"] as const,
|
|
/**
|
|
* Shared cache key for the rich `/api/insights/generate` advisor
|
|
* payload. Every surface that subscribes under this key shares the
|
|
* same cache so a regenerate on one surface refreshes the others
|
|
* without a second LLM round-trip.
|
|
*/
|
|
insightsAdvisor: () => ["insights", "advisor"] as const,
|
|
insightsBpStatus: (locale: string) =>
|
|
["insights", "blood-pressure-status", locale] as const,
|
|
insightsWeightStatus: (locale: string) =>
|
|
["insights", "weight-status", locale] as const,
|
|
insightsPulseStatus: (locale: string) =>
|
|
["insights", "pulse-status", locale] as const,
|
|
insightsBmiStatus: (locale: string) =>
|
|
["insights", "bmi-status", locale] as const,
|
|
insightsMoodStatus: (locale: string) =>
|
|
["insights", "mood-status", locale] as const,
|
|
insightsMedicationComplianceStatus: (locale: string) =>
|
|
["insights", "medication-compliance-status", locale] as const,
|
|
|
|
medications: () => ["medications"] as const,
|
|
medicationDetail: (id: string) => ["medications", id] as const,
|
|
medicationComplianceChart: (medicationId: string) =>
|
|
["compliance-chart-inline", medicationId] as const,
|
|
medicationPhaseConfig: (medicationId: string) =>
|
|
["phase-config", medicationId] as const,
|
|
medicationIntakeSummary: () => ["medications", "intake-summary"] as const,
|
|
|
|
gamificationAchievements: () => ["gamification", "achievements"] as const,
|
|
|
|
passkeys: () => ["passkeys"] as const,
|
|
|
|
notificationsPreferences: () => ["notifications", "preferences"] as const,
|
|
|
|
settingsGlobalServices: () => ["settings", "global-services"] as const,
|
|
settingsNtfy: () => ["settings", "ntfy"] as const,
|
|
|
|
tokens: () => ["tokens"] as const,
|
|
telegram: () => ["telegram"] as const,
|
|
telegramSettings: () => ["telegram", "settings"] as const,
|
|
withings: () => ["withings"] as const,
|
|
|
|
// v1.4.32 — workout list + detail caches. `workouts()` is the
|
|
// root key invalidated by the batch-ingest mutation; the recent +
|
|
// detail sub-keys ride underneath so the dashboard tile and the
|
|
// detail page share a cache slot with the list page.
|
|
workouts: () => ["workouts"] as const,
|
|
workoutsRecent: () => ["workouts", "recent"] as const,
|
|
workoutDetail: (id: string) => ["workouts", id] as const,
|
|
|
|
adminSettings: () => ["admin", "settings"] as const,
|
|
adminStatus: () => ["admin", "status"] as const,
|
|
adminUsers: () => ["admin", "users"] as const,
|
|
adminTokens: () => ["admin", "tokens"] as const,
|
|
adminAuditLog: (filter: unknown) => ["admin", "audit-log", filter] as const,
|
|
|
|
bugreportStatus: () => ["bugreport", "status"] as const,
|
|
|
|
/**
|
|
* v1.4.22 W5 reconcile (Code-LOW-5) — `["user", "dashboardWidgets"]`
|
|
* was duplicated as a literal at three call sites (dashboard,
|
|
* insights, settings/dashboard-layout). One typo turns into a
|
|
* silent cache miss + extra fetch; the centralised key defends
|
|
* against the same query-key-collision class as `analytics()`.
|
|
*/
|
|
dashboardWidgets: () => ["user", "dashboardWidgets"] as const,
|
|
|
|
/**
|
|
* v1.4.25 W5e — per-user, per-metric-class source priority. The
|
|
* Settings → Sources surface reads + writes this key; saving
|
|
* invalidates `analytics()` because the cumulative-metric aggregator
|
|
* folds the new priority into the SLEEP_DURATION daily total
|
|
* immediately.
|
|
*/
|
|
sourcePriority: () => ["auth", "source-priority"] as const,
|
|
};
|
|
|
|
/**
|
|
* Keys that should be invalidated when a measurement is created, updated or
|
|
* deleted. Kept here so dashboards, insights, and targets always stay in sync.
|
|
*/
|
|
export const measurementDependentKeys = [
|
|
queryKeys.measurements(),
|
|
queryKeys.analytics(),
|
|
queryKeys.insightsRoot(),
|
|
queryKeys.insightsTargets(),
|
|
queryKeys.gamificationAchievements(),
|
|
];
|
|
|
|
/**
|
|
* Keys that should be invalidated when a mood entry is created, updated or
|
|
* deleted.
|
|
*/
|
|
export const moodDependentKeys = [
|
|
queryKeys.moodEntries(),
|
|
queryKeys.moodAnalytics(),
|
|
queryKeys.insightsRoot(),
|
|
queryKeys.insightsTargets(),
|
|
queryKeys.gamificationAchievements(),
|
|
];
|
|
|
|
/**
|
|
* Keys invalidated when medications change (CRUD or intake).
|
|
*/
|
|
export const medicationDependentKeys = [
|
|
queryKeys.medications(),
|
|
queryKeys.analytics(),
|
|
queryKeys.insightsRoot(),
|
|
queryKeys.insightsTargets(),
|
|
queryKeys.medicationIntakeSummary(),
|
|
queryKeys.gamificationAchievements(),
|
|
];
|
|
|
|
/**
|
|
* Invalidate every key in the bundle in parallel. Use this from mutation
|
|
* `onSuccess` handlers so the call site stays a one-liner instead of repeating
|
|
* `Promise.all(keys.map(...))` everywhere.
|
|
*
|
|
* Uses `allSettled` so one transient network failure doesn't abort subsequent
|
|
* invalidations (cache would otherwise be left half-stale) and so the `void
|
|
* invalidateKeys(...)` fire-and-forget pattern in delete handlers never
|
|
* surfaces an unhandled rejection.
|
|
*/
|
|
export function invalidateKeys(
|
|
queryClient: QueryClient,
|
|
keys: readonly QueryKey[],
|
|
): Promise<PromiseSettledResult<unknown>[]> {
|
|
return Promise.allSettled(
|
|
keys.map((queryKey) => queryClient.invalidateQueries({ queryKey })),
|
|
);
|
|
}
|