mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
fix(insights): count failed fetches toward a bounded poll's ceiling
The status and advisor polls counted attempts on dataUpdateCount, which a failed fetch does not move, while the last good payload stayed in place and still said preparing. A request that kept failing polled an open page for as long as it stayed open. Attempts now include the failed fetches. The poll inventory moves from a comment into a guard held to every refetchInterval in the tree; four polls were missing from the comment.
This commit is contained in:
1 parent
b12bece491
commit
985372f711
7 files changed
+282
-48
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
nextAdvisorPollInterval,
|
||||
useInsightsAdvisorQuery,
|
||||
} from "@/components/insights/use-insights-advisor";
|
||||
import { pollAttemptCount } from "@/lib/queries/refetch-interval";
|
||||
import { useAnalyticsQuery } from "@/lib/queries/use-analytics-query";
|
||||
import { useInsightsLayoutQuery } from "@/hooks/use-insights-layout";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
@@ -89,7 +90,7 @@ export function InsightsLayoutShell({ children }: { children: ReactNode }) {
|
||||
refetchInterval: (query) =>
|
||||
nextAdvisorPollInterval(
|
||||
query.state.data?.revalidating,
|
||||
query.state.dataUpdateCount,
|
||||
pollAttemptCount(query.state),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useCallback, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { pollAttemptCount } from "@/lib/queries/refetch-interval";
|
||||
import type { InsightResult } from "@/lib/ai/types";
|
||||
// Type-only — the runtime schemas load lazily inside `fetchAdvisor` so
|
||||
// the zod module graph (`@/lib/ai/schema` is ~550 lines of zod builders)
|
||||
@@ -462,7 +463,7 @@ export function useInsightsAdvisorQuery(
|
||||
refetchInterval: (query) =>
|
||||
nextAdvisorPollInterval(
|
||||
query.state.data?.payload?.revalidating,
|
||||
query.state.dataUpdateCount,
|
||||
pollAttemptCount(query.state),
|
||||
settling,
|
||||
),
|
||||
});
|
||||
@@ -470,14 +471,12 @@ export function useInsightsAdvisorQuery(
|
||||
// `dataUpdateCount` lives on the query STATE (the refetchInterval callback
|
||||
// reads it there); the observer result only exposes `dataUpdatedAt`. Read
|
||||
// it imperatively from the cache where the settle machinery needs it.
|
||||
const readDataUpdateCount = useCallback(
|
||||
() =>
|
||||
queryClient
|
||||
.getQueryCache()
|
||||
.find({ queryKey: queryKeys.insightsAdvisor() })?.state
|
||||
.dataUpdateCount ?? 0,
|
||||
[queryClient],
|
||||
);
|
||||
const readDataUpdateCount = useCallback(() => {
|
||||
const state = queryClient
|
||||
.getQueryCache()
|
||||
.find({ queryKey: queryKeys.insightsAdvisor() })?.state;
|
||||
return state ? pollAttemptCount(state) : 0;
|
||||
}, [queryClient]);
|
||||
|
||||
// Apply the settle resolution the pure seam proves. Each poll result lands
|
||||
// in `query.data` (the poll's own cache write IS the fresh payload — no
|
||||
|
||||
Reference in new issue
Block a user