From aa5be37f97e94b304339c739d6308f5c594595cd Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Mon, 14 Oct 2024 19:59:33 -0700 Subject: [PATCH] fix index attempt refreshing automatically (#2791) Co-authored-by: Richard Kuo --- .../connector/[ccPairId]/IndexingAttemptsTable.tsx | 11 ++++++++++- web/src/app/admin/connector/[ccPairId]/page.tsx | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web/src/app/admin/connector/[ccPairId]/IndexingAttemptsTable.tsx b/web/src/app/admin/connector/[ccPairId]/IndexingAttemptsTable.tsx index 649ef1a97fd..51b7f8881ee 100644 --- a/web/src/app/admin/connector/[ccPairId]/IndexingAttemptsTable.tsx +++ b/web/src/app/admin/connector/[ccPairId]/IndexingAttemptsTable.tsx @@ -145,7 +145,7 @@ export function IndexingAttemptsTable({ ccPair }: { ccPair: CCPairFullInfo }) { if (!cachedBatches[0]) { fetchBatchData(0); } - }, [ccPair.id, page, cachedBatches, totalPages]); + }, [ccPair.id, page, cachedBatches, totalPages, fetchBatchData]); // This updates the data on the current page useEffect(() => { @@ -160,6 +160,15 @@ export function IndexingAttemptsTable({ ccPair }: { ccPair: CCPairFullInfo }) { } }, [page, cachedBatches]); + useEffect(() => { + const interval = setInterval(() => { + const batchNum = Math.floor((page - 1) / BATCH_SIZE); + fetchBatchData(batchNum); // Re-fetch the current batch data + }, 5000); // Refresh every 5 seconds + + return () => clearInterval(interval); // Cleanup on unmount + }, [page, fetchBatchData]); // Dependencies to ensure correct batch is fetched + // This updates the page number and manages the URL const updatePage = (newPage: number) => { setPage(newPage); diff --git a/web/src/app/admin/connector/[ccPairId]/page.tsx b/web/src/app/admin/connector/[ccPairId]/page.tsx index 2c738c03f9b..9cdf7c83ec2 100644 --- a/web/src/app/admin/connector/[ccPairId]/page.tsx +++ b/web/src/app/admin/connector/[ccPairId]/page.tsx @@ -74,7 +74,7 @@ function Main({ ccPairId }: { ccPairId: number }) { ) { finishConnectorDeletion(); } - }, [isLoading, ccPair, error, hasLoadedOnce]); + }, [isLoading, ccPair, error, hasLoadedOnce, finishConnectorDeletion]); const handleNameChange = (e: React.ChangeEvent) => { setEditableName(e.target.value);