From 6b1058e754c402c85e72bf2cd3a9635360e2f0d6 Mon Sep 17 00:00:00 2001 From: Wes Date: Sat, 15 Aug 2026 08:40:07 -0600 Subject: [PATCH] perf(desktop): retain channel page provenance with warm rows Keep the authoritative channel window alive for the same hour as its projected message cache so revisits cannot lose loader provenance first. Co-authored-by: Carl Signed-off-by: Wes --- desktop/src/features/messages/hooks.ts | 7 ++++++- .../features/messages/lib/projectChannelWindow.test.mjs | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/desktop/src/features/messages/hooks.ts b/desktop/src/features/messages/hooks.ts index 4eeae402a..03e5378d8 100644 --- a/desktop/src/features/messages/hooks.ts +++ b/desktop/src/features/messages/hooks.ts @@ -228,6 +228,8 @@ export function resolveThreadReplyTarget( }; } +export const CHANNEL_TIMELINE_GC_TIME_MS = 60 * 60 * 1_000; + export function useChannelWindowQuery(channel: Channel | null) { const queryClient = useQueryClient(); const queryKey = channelWindowKey(channel?.id ?? "none"); @@ -238,6 +240,9 @@ export function useChannelWindowQuery(channel: Channel | null) { queryClient.getQueryData(queryKey) ?? emptyChannelWindowStore(), staleTime: Number.POSITIVE_INFINITY, + // Page provenance determines whether cached rows (including known-empty) + // are warm enough to paint. Retain it for exactly as long as those rows. + gcTime: CHANNEL_TIMELINE_GC_TIME_MS, }); } @@ -368,7 +373,7 @@ export function useChannelMessagesQuery(channel: Channel | null) { ); }, staleTime: 5 * 60 * 1_000, - gcTime: 60 * 60 * 1_000, + gcTime: CHANNEL_TIMELINE_GC_TIME_MS, }); } diff --git a/desktop/src/features/messages/lib/projectChannelWindow.test.mjs b/desktop/src/features/messages/lib/projectChannelWindow.test.mjs index 8890e610a..97b00f451 100644 --- a/desktop/src/features/messages/lib/projectChannelWindow.test.mjs +++ b/desktop/src/features/messages/lib/projectChannelWindow.test.mjs @@ -3,6 +3,7 @@ import test from "node:test"; import { QueryClient, QueryObserver } from "@tanstack/react-query"; import { + CHANNEL_TIMELINE_GC_TIME_MS, reconcileFetchedChannelWindow, reconcileFetchedChannelWindowPages, } from "../hooks.ts"; @@ -54,6 +55,10 @@ function newestPage(rows) { }; } +test("channel page provenance is retained for the full warm-row lifetime", () => { + assert.equal(CHANNEL_TIMELINE_GC_TIME_MS, 60 * 60 * 1_000); +}); + function createHarness() { const client = new QueryClient({ defaultOptions: { queries: { retry: false } },