feat: replace server-side Redis caching with TanStack Query AsyncStoragePersister

Consolidate two overlapping cache systems (broken TanStack persister + per-query Redis hash + pub/sub) into one: TanStack Query as single source of truth with Redis as its persistence layer via createAsyncStoragePersister.

- Replace QueryClientProvider with PersistQueryClientProvider backed by Redis
- Set global query defaults (staleTime: 0, refetchInterval: 30s, gcTime: 24h)
- Remove all per-widget staleTime/refetchInterval/retry/refetchOnWindowFocus overrides
- Replace cached request handlers with simplified fetch-only versions
- Remove all tRPC subscription procedures and useSubscription calls in favor of polling
- Delete 20 cron jobs that only pre-warmed server-side cache
- Simplify Redis from per-query hash to single blob per user+board
This commit is contained in:
Thomas Camlong committed 2026-06-24 14:55:17 +02:00
1 parent 58cb65cb3a
commit 6416080b79
165 files changed
+546 -3456

No files matched your search

+6 -24
View File
@@ -1,4 +1,3 @@
import { observable } from "@trpc/server/observable";
import { z } from "zod/v4";
import { createLogger } from "@homarr/core/infrastructure/logs";
@@ -46,7 +45,7 @@ export const umamiRouter = createTRPCRouter({
timeFrame: input.timeFrame,
eventName: input.eventName,
});
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data, timestamp } = await innerHandler.getDataAsync();
return {
integrationId: integration.id,
@@ -67,7 +66,7 @@ export const umamiRouter = createTRPCRouter({
.query(async ({ ctx, input }) => {
try {
const innerHandler = umamiEventNamesRequestHandler.handler(ctx.integration, { websiteId: input.websiteId });
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data } = await innerHandler.getDataAsync();
return data;
} catch (error) {
logger.warn(
@@ -93,7 +92,7 @@ export const umamiRouter = createTRPCRouter({
timeFrame: input.timeFrame,
limit: input.limit,
});
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data } = await innerHandler.getDataAsync();
return data;
} catch (error) {
logger.warn(
@@ -123,7 +122,7 @@ export const umamiRouter = createTRPCRouter({
timeFrame: input.timeFrame,
limit: input.limit,
});
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data } = await innerHandler.getDataAsync();
return data;
} catch (error) {
logger.warn(
@@ -154,7 +153,7 @@ export const umamiRouter = createTRPCRouter({
timeFrame: input.timeFrame,
eventNames: sortedNames,
});
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data } = await innerHandler.getDataAsync();
return data;
} catch (error) {
logger.warn(
@@ -176,7 +175,7 @@ export const umamiRouter = createTRPCRouter({
const innerHandler = umamiActiveVisitorsRequestHandler.handler(ctx.integration, {
websiteId: input.websiteId,
});
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
const { data } = await innerHandler.getDataAsync();
return data;
} catch (error) {
logger.warn(
@@ -185,21 +184,4 @@ export const umamiRouter = createTRPCRouter({
return 0;
}
}),
subscribeActiveVisitors: publicProcedure
.input(z.object({ websiteId: z.string() }))
.concat(createOneIntegrationMiddleware("query", "umami"))
.subscription(({ ctx, input }) => {
return observable<number>((emit) => {
const innerHandler = umamiActiveVisitorsRequestHandler.handler(ctx.integration, {
websiteId: input.websiteId,
});
const unsubscribe = innerHandler.subscribe((count) => {
emit.next(count);
});
return () => {
unsubscribe();
};
});
}),
});