From 864b4155a6b840a3b9d194f7c9daac351850f806 Mon Sep 17 00:00:00 2001 From: Alan Daniel Date: Tue, 26 May 2026 16:42:26 -0400 Subject: [PATCH] Relax GitHub cache policy for fresher page data. Shorten server and client TTLs and re-enable refetch-on-focus/mount so pages hit the GitHub API directly instead of relying mainly on webhook revalidation. --- .../components/pulls/review/review-page.tsx | 36 +++++++------------ .../src/components/repo/commit-page.tsx | 8 ++--- .../src/components/repo/latest-commit-bar.tsx | 2 -- apps/dashboard/src/lib/github-cache-policy.ts | 30 ++++++++-------- apps/dashboard/src/lib/github-cache.test.ts | 2 +- apps/dashboard/src/lib/github-cache.ts | 4 +-- apps/dashboard/src/lib/query-client.tsx | 1 - 7 files changed, 34 insertions(+), 49 deletions(-) diff --git a/apps/dashboard/src/components/pulls/review/review-page.tsx b/apps/dashboard/src/components/pulls/review/review-page.tsx index 91da24e..e50716d 100644 --- a/apps/dashboard/src/components/pulls/review/review-page.tsx +++ b/apps/dashboard/src/components/pulls/review/review-page.tsx @@ -138,17 +138,11 @@ export function ReviewPage() { // Stable store for active file — updates bypass ReviewPage renders entirely const activeFileStore = useRef(createActiveFileStore(null)).current; - const pageQuery = useQuery({ - ...githubPullPageQueryOptions(scope, input), - refetchOnMount: false, - refetchOnWindowFocus: false, - }); + const pageQuery = useQuery(githubPullPageQueryOptions(scope, input)); - const fileSummariesQuery = useInfiniteQuery({ - ...githubPullFileSummariesQueryOptions(scope, input), - refetchOnMount: false, - refetchOnWindowFocus: false, - }); + const fileSummariesQuery = useInfiniteQuery( + githubPullFileSummariesQueryOptions(scope, input), + ); // Auto-fetch remaining pages so the sidebar streams in the whole tree // without requiring user interaction. Each page is ~100 files, so for a @@ -167,11 +161,9 @@ export function ReviewPage() { fileSummariesQuery.fetchNextPage, ]); - const filesQuery = useInfiniteQuery({ - ...githubPullFilesInfiniteQueryOptions(scope, input), - refetchOnMount: false, - refetchOnWindowFocus: false, - }); + const filesQuery = useInfiniteQuery( + githubPullFilesInfiniteQueryOptions(scope, input), + ); // Auto-fetch remaining pages of patches in the background so that by the // time the user scrolls deeper into the PR, the data is already there. @@ -188,14 +180,12 @@ export function ReviewPage() { ]); const hasDiffPayload = filesQuery.data !== undefined; - const reviewCommentsQuery = useQuery({ - ...githubPullReviewCommentsQueryOptions(scope, input), - refetchOnWindowFocus: false, - }); - const threadStatusesQuery = useQuery({ - ...githubReviewThreadStatusesQueryOptions(scope, input), - refetchOnWindowFocus: false, - }); + const reviewCommentsQuery = useQuery( + githubPullReviewCommentsQueryOptions(scope, input), + ); + const threadStatusesQuery = useQuery( + githubReviewThreadStatusesQueryOptions(scope, input), + ); useGitHubSignalStream(webhookRefreshTargets); const pr = pageQuery.data?.detail ?? null; diff --git a/apps/dashboard/src/components/repo/commit-page.tsx b/apps/dashboard/src/components/repo/commit-page.tsx index 584fa12..63fb772 100644 --- a/apps/dashboard/src/components/repo/commit-page.tsx +++ b/apps/dashboard/src/components/repo/commit-page.tsx @@ -69,11 +69,9 @@ export function CommitPage() { const activeFileStore = useRef(createActiveFileStore(null)).current; const diffPaneRef = useRef(null); - const commitQuery = useQuery({ - ...githubRepoCommitQueryOptions(scope, { owner, repo, sha }), - refetchOnMount: false, - refetchOnWindowFocus: false, - }); + const commitQuery = useQuery( + githubRepoCommitQueryOptions(scope, { owner, repo, sha }), + ); const commit = commitQuery.data; diff --git a/apps/dashboard/src/components/repo/latest-commit-bar.tsx b/apps/dashboard/src/components/repo/latest-commit-bar.tsx index 9d056b9..be9066e 100644 --- a/apps/dashboard/src/components/repo/latest-commit-bar.tsx +++ b/apps/dashboard/src/components/repo/latest-commit-bar.tsx @@ -39,8 +39,6 @@ export function LatestCommitBar({ ref === defaultBranch && defaultBranchTip != null ? defaultBranchTip : undefined, - refetchOnMount: false, - refetchOnWindowFocus: false, }); const commit = tipQuery.data; diff --git a/apps/dashboard/src/lib/github-cache-policy.ts b/apps/dashboard/src/lib/github-cache-policy.ts index 6ed5862..0cff917 100644 --- a/apps/dashboard/src/lib/github-cache-policy.ts +++ b/apps/dashboard/src/lib/github-cache-policy.ts @@ -1,59 +1,59 @@ export const githubCachePolicy = { viewer: { - staleTimeMs: 30 * 60 * 1000, + staleTimeMs: 5 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, reposList: { - staleTimeMs: 10 * 60 * 1000, + staleTimeMs: 2 * 60 * 1000, gcTimeMs: 12 * 60 * 60 * 1000, }, list: { - staleTimeMs: 2 * 60 * 1000, + staleTimeMs: 30 * 1000, gcTimeMs: 60 * 60 * 1000, }, - /** User-scoped "My pulls/issues/reviews" aggregates — shorter TTL + faster webhook alignment */ + /** User-scoped "My pulls/issues/reviews" aggregates */ mine: { - staleTimeMs: 30 * 1000, + staleTimeMs: 10 * 1000, gcTimeMs: 15 * 60 * 1000, }, detail: { - staleTimeMs: 30 * 1000, + staleTimeMs: 5 * 1000, gcTimeMs: 10 * 60 * 1000, }, activity: { - staleTimeMs: 20 * 1000, + staleTimeMs: 5 * 1000, gcTimeMs: 10 * 60 * 1000, }, userActivity: { - staleTimeMs: 5 * 60 * 1000, + staleTimeMs: 60 * 1000, gcTimeMs: 30 * 60 * 1000, }, status: { - staleTimeMs: 15 * 1000, + staleTimeMs: 5 * 1000, gcTimeMs: 5 * 60 * 1000, }, workflowRun: { - staleTimeMs: 15 * 1000, + staleTimeMs: 5 * 1000, gcTimeMs: 5 * 60 * 1000, }, contributions: { - staleTimeMs: 60 * 60 * 1000, + staleTimeMs: 15 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, repoMeta: { - staleTimeMs: 30 * 60 * 1000, + staleTimeMs: 5 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, repoParticipation: { - staleTimeMs: 60 * 60 * 1000, + staleTimeMs: 15 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, installationAccess: { - staleTimeMs: 30 * 60 * 1000, + staleTimeMs: 5 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, repoProtection: { - staleTimeMs: 30 * 60 * 1000, + staleTimeMs: 5 * 60 * 1000, gcTimeMs: 24 * 60 * 60 * 1000, }, } as const; diff --git a/apps/dashboard/src/lib/github-cache.test.ts b/apps/dashboard/src/lib/github-cache.test.ts index 61f553c..ac0b8ae 100644 --- a/apps/dashboard/src/lib/github-cache.test.ts +++ b/apps/dashboard/src/lib/github-cache.test.ts @@ -363,7 +363,7 @@ describe("getOrRevalidateGitHubResource", () => { expect(result).toEqual({ login: "adn" }); const updatedEntry = await store.get("user-1::viewer::null"); - expect(updatedEntry?.freshUntil).toBe(300_500); + expect(updatedEntry?.freshUntil).toBe(90_500); expect(updatedEntry?.rateLimitRemaining).toBe(10); }); diff --git a/apps/dashboard/src/lib/github-cache.ts b/apps/dashboard/src/lib/github-cache.ts index 0f9b6d1..8e2633d 100644 --- a/apps/dashboard/src/lib/github-cache.ts +++ b/apps/dashboard/src/lib/github-cache.ts @@ -88,8 +88,8 @@ type GetOrRevalidateGitHubResourceOptions = { const DEFAULT_GITHUB_PAYLOAD_RETENTION_SECONDS = 7 * 24 * 60 * 60; const GITHUB_RATE_LIMIT_LOW_REMAINING = 100; const GITHUB_RATE_LIMIT_CRITICAL_REMAINING = 25; -const GITHUB_RATE_LIMIT_LOW_FRESH_FLOOR_MS = 2 * 60 * 1000; -const GITHUB_RATE_LIMIT_CRITICAL_FRESH_FLOOR_MS = 5 * 60 * 1000; +const GITHUB_RATE_LIMIT_LOW_FRESH_FLOOR_MS = 45 * 1000; +const GITHUB_RATE_LIMIT_CRITICAL_FRESH_FLOOR_MS = 90 * 1000; const GITHUB_RATE_LIMIT_RESET_BUFFER_MS = 5 * 1000; const GITHUB_STALE_IF_RATE_LIMITED_FALLBACK_MS = 60 * 1000; diff --git a/apps/dashboard/src/lib/query-client.tsx b/apps/dashboard/src/lib/query-client.tsx index 9a0fb62..490540f 100644 --- a/apps/dashboard/src/lib/query-client.tsx +++ b/apps/dashboard/src/lib/query-client.tsx @@ -300,7 +300,6 @@ export function createAppQueryClient() { const queryClient = new QueryClient({ defaultOptions: { queries: { - refetchOnWindowFocus: false, retry: 1, networkMode: "online", },