yangdx commited on
Commit
1a45912
·
1 Parent(s): 1048e74

Optimze document status change monitor

Browse files
lightrag_webui/src/features/DocumentManager.tsx CHANGED
@@ -361,20 +361,8 @@ export default function DocumentManager() {
361
  // Check again if component is still mounted after the request completes
362
  if (!isMountedRef.current) return;
363
 
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
-
373
  // Only update state if component is still mounted
374
  if (isMountedRef.current) {
375
- // Update previous status counts
376
- prevStatusCounts.current = newStatusCounts
377
-
378
  // Update docs state
379
  if (docs && docs.statuses) {
380
  const numDocuments = Object.values(docs.statuses).reduce(
@@ -449,6 +437,32 @@ export default function DocumentManager() {
449
  }
450
  }, [health, fetchDocuments, t, currentTab])
451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  // Add dependency on sort state to re-render when sort changes
453
  useEffect(() => {
454
  // This effect ensures the component re-renders when sort state changes
 
361
  // Check again if component is still mounted after the request completes
362
  if (!isMountedRef.current) return;
363
 
 
 
 
 
 
 
 
 
 
364
  // Only update state if component is still mounted
365
  if (isMountedRef.current) {
 
 
 
366
  // Update docs state
367
  if (docs && docs.statuses) {
368
  const numDocuments = Object.values(docs.statuses).reduce(
 
437
  }
438
  }, [health, fetchDocuments, t, currentTab])
439
 
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
+
466
  // Add dependency on sort state to re-render when sort changes
467
  useEffect(() => {
468
  // This effect ensures the component re-renders when sort state changes