From 43ccb7d113bd723182e83a4579271c66682fd154 Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 26 Mar 2025 14:02:20 +0800 Subject: [PATCH] feat(DocumentManager): optimize document status monitoring - Improve document status change detection by caching previous counts and properly handling null states. - This ensures more accurate pipeline status updates. --- .../documents/PipelineStatusDialog.tsx | 7 +++- .../src/features/DocumentManager.tsx | 34 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx b/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx index 50e1d842..83ec369b 100644 --- a/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx +++ b/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx @@ -8,7 +8,8 @@ import { AlertDialogContent, AlertDialogHeader, AlertDialogTitle, - AlertDialogOverlay + AlertDialogOverlay, + AlertDialogDescription } from '@/components/ui/AlertDialog' import Button from '@/components/ui/Button' import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag' @@ -144,6 +145,10 @@ export default function PipelineStatusDialog({ + + + {t('documentPanel.pipelineStatus.description')} + {/* Status Content */}
diff --git a/lightrag_webui/src/features/DocumentManager.tsx b/lightrag_webui/src/features/DocumentManager.tsx index cee5add3..2f8264ac 100644 --- a/lightrag_webui/src/features/DocumentManager.tsx +++ b/lightrag_webui/src/features/DocumentManager.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from 'react' +import { useState, useEffect, useCallback, useRef } from 'react' import { useTranslation } from 'react-i18next' import { useSettingsStore } from '@/stores/settings' import Button from '@/components/ui/Button' @@ -97,6 +97,14 @@ export default function DocumentManager() { const showFileName = useSettingsStore.use.showFileName() const setShowFileName = useSettingsStore.use.setShowFileName() + // Store previous status counts + const prevStatusCounts = useRef({ + processed: 0, + processing: 0, + pending: 0, + failed: 0 + }) + // Add pulse style to document useEffect(() => { const style = document.createElement('style') @@ -110,8 +118,30 @@ export default function DocumentManager() { const fetchDocuments = useCallback(async () => { try { const docs = await getDocuments() + + // Get new status counts (treat null as all zeros) + const newStatusCounts = { + processed: docs?.statuses?.processed?.length || 0, + processing: docs?.statuses?.processing?.length || 0, + pending: docs?.statuses?.pending?.length || 0, + failed: docs?.statuses?.failed?.length || 0 + } + + // Check if any status count has changed + const hasStatusCountChange = (Object.keys(newStatusCounts) as Array).some( + status => newStatusCounts[status] !== prevStatusCounts.current[status] + ) + + // Trigger health check if changes detected + if (hasStatusCountChange) { + useBackendState.getState().check() + } + + // Update previous status counts + prevStatusCounts.current = newStatusCounts + + // Update docs state if (docs && docs.statuses) { - // compose all documents count const numDocuments = Object.values(docs.statuses).reduce( (acc, status) => acc + status.length, 0