hotpatch: remove consitent 2 sec interval api call to logs summary endpoint

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-12-28 15:52:58 -08:00
parent 0e1ea9c30f
commit 46eb63fa11
4 changed files with 27 additions and 60 deletions

View file

@ -134,8 +134,11 @@ export default function DocumentsTable() {
toast.success(t("refresh_success") || "Documents refreshed");
}, [debouncedSearch, refetchSearch, refetchDocuments, t]);
// Set up polling for active tasks
const { summary } = useLogsSummary(searchSpaceId, 24, { refetchInterval: 5000 });
// Set up smart polling for active tasks - only polls when tasks are in progress
const { summary } = useLogsSummary(searchSpaceId, 24, {
enablePolling: true,
refetchInterval: 5000, // Poll every 5 seconds when tasks are active
});
const activeTasksCount = summary?.active_tasks.length || 0;
const prevActiveTasksCount = useRef(activeTasksCount);

View file

@ -80,8 +80,10 @@ export function NavNotes({
const [isAllNotesSidebarOpen, setIsAllNotesSidebarOpen] = useState(false);
// Poll for active reindexing tasks to show inline loading indicators
// Smart polling: only polls when there are active tasks, stops when idle
const { summary } = useLogsSummary(searchSpaceId ? Number(searchSpaceId) : 0, 24, {
refetchInterval: 2000,
enablePolling: true,
refetchInterval: 5000, // Poll every 5 seconds when tasks are active
});
// Create a Set of document IDs that are currently being reindexed

View file

@ -118,12 +118,15 @@ export function useLogs(searchSpaceId?: number, filters: LogFilters = {}) {
};
}
// Separate hook for log summary with optional polling support for document processing indicator UI
// Separate hook for log summary with smart polling support for document processing indicator UI
// Polling only happens when there are active tasks, otherwise it stops to save resources
export function useLogsSummary(
searchSpaceId: number,
hours: number = 24,
options: { refetchInterval?: number } = {}
options: { refetchInterval?: number; enablePolling?: boolean } = {}
) {
const { enablePolling = false, refetchInterval = 10000 } = options;
const {
data: summary,
isLoading: loading,
@ -138,9 +141,20 @@ export function useLogsSummary(
}),
enabled: !!searchSpaceId,
staleTime: 3 * 60 * 1000,
// Enable refetch interval for document processing indicator polling
refetchInterval:
options.refetchInterval && options.refetchInterval > 0 ? options.refetchInterval : undefined,
// Smart polling: only poll when there are active tasks and polling is enabled
// This prevents unnecessary API calls when nothing is being processed
refetchInterval: enablePolling
? (query) => {
const data = query.state.data;
// Only continue polling if there are active tasks
if (data?.active_tasks && data.active_tasks.length > 0) {
return refetchInterval;
}
// No active tasks - stop polling but check again after a longer interval
// to catch any newly started tasks
return 30000; // Check every 30 seconds when idle
}
: undefined,
});
return { summary, loading, error, refreshSummary: refetch };