Skip to content

Commit d1cd667

Browse files
authored
fix: Optimize live tail memory (#764)
1 parent bbde4bc commit d1cd667

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/app/src/DBSearchPage.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ import {
4242
Stack,
4343
Text,
4444
} from '@mantine/core';
45-
import { useDebouncedCallback, useDisclosure } from '@mantine/hooks';
45+
import {
46+
useDebouncedCallback,
47+
useDisclosure,
48+
useDocumentVisibility,
49+
} from '@mantine/hooks';
4650
import { notifications } from '@mantine/notifications';
4751
import { useIsFetching } from '@tanstack/react-query';
4852
import CodeMirror from '@uiw/react-codemirror';
@@ -802,12 +806,14 @@ function DBSearchPage() {
802806
queryKey: [QUERY_KEY_PREFIX],
803807
}) > 0;
804808

809+
const isTabVisible = useDocumentVisibility();
810+
805811
useLiveUpdate({
806812
isLive,
807813
interval: 1000 * 60 * 15,
808814
refreshFrequency: 4000,
809815
onTimeRangeSelect,
810-
pause: isAnyQueryFetching || !queryReady,
816+
pause: isAnyQueryFetching || !queryReady || !isTabVisible,
811817
});
812818

813819
// This ensures we only render this conditionally on the client

packages/app/src/hooks/useOffsetPaginatedQuery.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export default function useOffsetPaginatedQuery(
303303
gcTime: isLive ? ms('30s') : ms('5m'), // more aggressive gc for live data, since it can end up holding lots of data
304304
retry: 1,
305305
refetchOnWindowFocus: false,
306+
maxPages: isLive ? 5 : undefined, // Limit number of pages kept in cache for live data
306307
});
307308

308309
const flattenedData = useMemo(() => flattenData(data), [data]);

0 commit comments

Comments
 (0)