From 9fbe705d06fb2f2225e7be91fdc7479cc7746a76 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 28 Mar 2025 16:58:47 -0600 Subject: [PATCH] more updates --- .../api/buster_rest/metrics/queryRequests.ts | 2 ++ .../BusterReactQuery/getQueryClient.ts | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/web/src/api/buster_rest/metrics/queryRequests.ts b/web/src/api/buster_rest/metrics/queryRequests.ts index 1c4079712..a8cae1293 100644 --- a/web/src/api/buster_rest/metrics/queryRequests.ts +++ b/web/src/api/buster_rest/metrics/queryRequests.ts @@ -118,6 +118,8 @@ export const useGetMetricData = ({ return getMetricData({ id, version_number }); }); + console.log('data here!'); + return useQuery({ ...metricsQueryKeys.metricsGetData(id, version_number), queryFn diff --git a/web/src/context/BusterReactQuery/getQueryClient.ts b/web/src/context/BusterReactQuery/getQueryClient.ts index d3025e4d1..a7cbee8e0 100644 --- a/web/src/context/BusterReactQuery/getQueryClient.ts +++ b/web/src/context/BusterReactQuery/getQueryClient.ts @@ -8,12 +8,9 @@ type OpenErrorNotification = ReturnType['openErro const PREFETCH_STALE_TIME = 1000 * 10; // 10 seconds const ERROR_RETRY_DELAY = 1 * 1000; // 1 second delay after error const GC_TIME = 1000 * 60 * 60 * 24 * 3; // 24 hours - matches persistence duration -const refetchOnMountRecord: Record = PERMANENT_QUERIES.reduce< - Record ->((acc, query) => { - acc[query] = 1; - return acc; -}, {}); + +// Track queries that have already mounted +const mountedQueries = new Set(); function makeQueryClient(params?: { openErrorNotification?: OpenErrorNotification; @@ -36,15 +33,21 @@ function makeQueryClient(params?: { return false; }, retryDelay: ERROR_RETRY_DELAY, - refetchOnMount: (queryClient) => { - if (queryClient.isActive()) { - if (queryClient.isActive() && !(queryClient.queryHash in refetchOnMountRecord)) { - refetchOnMountRecord[queryClient.queryHash] = 0; - } - refetchOnMountRecord[queryClient.queryHash]++; - return refetchOnMountRecord[queryClient.queryHash] <= 1 ? 'always' : true; + refetchOnMount: (query) => { + console.log(query.queryHash, query.state.dataUpdatedAt); + if (!query.state.dataUpdatedAt) { + // No data has been fetched yet + return true; } - return true; + + if (!mountedQueries.has(query.queryHash) && query.isActive()) { + // First time mounting this query + mountedQueries.add(query.queryHash); + return 'always'; + } + + // Query has mounted before, use default stale time behavior + return query.state.dataUpdatedAt < Date.now() - PREFETCH_STALE_TIME; } }, mutations: {