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.
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
|||||||
AlertDialogContent,
|
AlertDialogContent,
|
||||||
AlertDialogHeader,
|
AlertDialogHeader,
|
||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
AlertDialogOverlay
|
AlertDialogOverlay,
|
||||||
|
AlertDialogDescription
|
||||||
} from '@/components/ui/AlertDialog'
|
} from '@/components/ui/AlertDialog'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag'
|
import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag'
|
||||||
@@ -144,6 +145,10 @@ export default function PipelineStatusDialog({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
|
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t('documentPanel.pipelineStatus.description')}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
|
||||||
{/* Status Content */}
|
{/* Status Content */}
|
||||||
<div className="space-y-4 pt-4">
|
<div className="space-y-4 pt-4">
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useSettingsStore } from '@/stores/settings'
|
import { useSettingsStore } from '@/stores/settings'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
@@ -97,6 +97,14 @@ export default function DocumentManager() {
|
|||||||
const showFileName = useSettingsStore.use.showFileName()
|
const showFileName = useSettingsStore.use.showFileName()
|
||||||
const setShowFileName = useSettingsStore.use.setShowFileName()
|
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
|
// Add pulse style to document
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const style = document.createElement('style')
|
const style = document.createElement('style')
|
||||||
@@ -110,8 +118,30 @@ export default function DocumentManager() {
|
|||||||
const fetchDocuments = useCallback(async () => {
|
const fetchDocuments = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const docs = await getDocuments()
|
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<keyof typeof newStatusCounts>).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) {
|
if (docs && docs.statuses) {
|
||||||
// compose all documents count
|
|
||||||
const numDocuments = Object.values(docs.statuses).reduce(
|
const numDocuments = Object.values(docs.statuses).reduce(
|
||||||
(acc, status) => acc + status.length,
|
(acc, status) => acc + status.length,
|
||||||
0
|
0
|
||||||
|
Reference in New Issue
Block a user