Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix index attempt refreshing automatically #2791

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion web/src/app/admin/connector/[ccPairId]/IndexingAttemptsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Adding fetchBatchData to the dependency array may cause unnecessary re-renders. Consider using useCallback for fetchBatchData


// This updates the data on the current page
useEffect(() => {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/admin/connector/[ccPairId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Main({ ccPairId }: { ccPairId: number }) {
) {
finishConnectorDeletion();
}
}, [isLoading, ccPair, error, hasLoadedOnce]);
}, [isLoading, ccPair, error, hasLoadedOnce, finishConnectorDeletion]);

const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setEditableName(e.target.value);
Expand Down