Skip to content

Commit 13eeb9a

Browse files
committed
Optimze document status change monitor
1 parent 0ec5ada commit 13eeb9a

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

lightrag_webui/src/features/DocumentManager.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,8 @@ export default function DocumentManager() {
361361
// Check again if component is still mounted after the request completes
362362
if (!isMountedRef.current) return;
363363

364-
// Get new status counts (treat null as all zeros)
365-
const newStatusCounts = {
366-
processed: docs?.statuses?.processed?.length || 0,
367-
processing: docs?.statuses?.processing?.length || 0,
368-
pending: docs?.statuses?.pending?.length || 0,
369-
failed: docs?.statuses?.failed?.length || 0
370-
}
371-
372-
373364
// Only update state if component is still mounted
374365
if (isMountedRef.current) {
375-
// Update previous status counts
376-
prevStatusCounts.current = newStatusCounts
377-
378366
// Update docs state
379367
if (docs && docs.statuses) {
380368
const numDocuments = Object.values(docs.statuses).reduce(
@@ -449,6 +437,32 @@ export default function DocumentManager() {
449437
}
450438
}, [health, fetchDocuments, t, currentTab])
451439

440+
// Monitor docs changes to check status counts and trigger health check if needed
441+
useEffect(() => {
442+
if (!docs) return;
443+
444+
// Get new status counts
445+
const newStatusCounts = {
446+
processed: docs?.statuses?.processed?.length || 0,
447+
processing: docs?.statuses?.processing?.length || 0,
448+
pending: docs?.statuses?.pending?.length || 0,
449+
failed: docs?.statuses?.failed?.length || 0
450+
}
451+
452+
// Check if any status count has changed
453+
const hasStatusCountChange = (Object.keys(newStatusCounts) as Array<keyof typeof newStatusCounts>).some(
454+
status => newStatusCounts[status] !== prevStatusCounts.current[status]
455+
)
456+
457+
// Trigger health check if changes detected and component is still mounted
458+
if (hasStatusCountChange && isMountedRef.current) {
459+
useBackendState.getState().check()
460+
}
461+
462+
// Update previous status counts
463+
prevStatusCounts.current = newStatusCounts
464+
}, [docs]);
465+
452466
// Add dependency on sort state to re-render when sort changes
453467
useEffect(() => {
454468
// This effect ensures the component re-renders when sort state changes

0 commit comments

Comments
 (0)