mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
fix(insights,cache): surface revalidation to clients and evict on interactive writes
Stale-served insights responses now carry a revalidating flag; the advisor and comprehensive queries poll on a bounded 25 s cadence until the background warm lands, so an open session converges instead of pinning yesterday's briefing for an hour. Interactive measurement writes (single create, edit, delete, bulk-delete, restore) hard-evict the analytics cache so a manually entered value is reflected on the next read; background batch sync keeps the mark-stale path. The visit-triggered force warm collapses to one job per user instead of one per locale, and the umami script proxy failure now annotates a named action with the failure reason instead of a bare flag.
This commit is contained in:
1 parent
78fe82e348
commit
03453aaed2
23 files changed
+461
-55
No files matched your search
Vendored
+24
-1
@@ -522,6 +522,29 @@ export async function cachedSwr<T>(
|
||||
annotateFn?: (fields: { meta: Record<string, unknown> }) => void,
|
||||
ttlMsOverride?: number,
|
||||
): Promise<T> {
|
||||
const { value } = await cachedSwrWithMeta(
|
||||
cache,
|
||||
key,
|
||||
builder,
|
||||
annotateFn,
|
||||
ttlMsOverride,
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.16.7 — `cachedSwr` variant that also surfaces the read outcome so
|
||||
* a route can mark a stale-served response (`outcome === "stale"`) as
|
||||
* `revalidating` for the client. Non-breaking addition: `cachedSwr`
|
||||
* keeps its value-only shape and delegates here.
|
||||
*/
|
||||
export async function cachedSwrWithMeta<T>(
|
||||
cache: ServerCache<T>,
|
||||
key: string,
|
||||
builder: () => Promise<T>,
|
||||
annotateFn?: (fields: { meta: Record<string, unknown> }) => void,
|
||||
ttlMsOverride?: number,
|
||||
): Promise<{ value: T; outcome: "hit" | "stale" | "miss" | "stampede" }> {
|
||||
const { value, outcome } = await cache.wrapSwr(key, builder, ttlMsOverride);
|
||||
if (annotateFn) {
|
||||
const name = cache.stats().name;
|
||||
@@ -532,7 +555,7 @@ export async function cachedSwr<T>(
|
||||
},
|
||||
});
|
||||
}
|
||||
return value;
|
||||
return { value, outcome };
|
||||
}
|
||||
|
||||
/** Test helper — reset every cache in the registry. */
|
||||
|
||||
Reference in new issue
Block a user