yangdx commited on
Commit
c5f15e5
·
1 Parent(s): 6227ba2

feat(DocumentManager): optimize document status monitoring

Browse files

- Improve document status change detection by caching previous counts and properly handling null states.
- This ensures more accurate pipeline status updates.

lightrag_webui/src/components/documents/PipelineStatusDialog.tsx CHANGED
@@ -8,7 +8,8 @@ import {
8
  AlertDialogContent,
9
  AlertDialogHeader,
10
  AlertDialogTitle,
11
- AlertDialogOverlay
 
12
  } from '@/components/ui/AlertDialog'
13
  import Button from '@/components/ui/Button'
14
  import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag'
@@ -144,6 +145,10 @@ export default function PipelineStatusDialog({
144
  </Button>
145
  </div>
146
  </AlertDialogHeader>
 
 
 
 
147
 
148
  {/* Status Content */}
149
  <div className="space-y-4 pt-4">
 
8
  AlertDialogContent,
9
  AlertDialogHeader,
10
  AlertDialogTitle,
11
+ AlertDialogOverlay,
12
+ AlertDialogDescription
13
  } from '@/components/ui/AlertDialog'
14
  import Button from '@/components/ui/Button'
15
  import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag'
 
145
  </Button>
146
  </div>
147
  </AlertDialogHeader>
148
+
149
+ <AlertDialogDescription>
150
+ {t('documentPanel.pipelineStatus.description')}
151
+ </AlertDialogDescription>
152
 
153
  {/* Status Content */}
154
  <div className="space-y-4 pt-4">
lightrag_webui/src/features/DocumentManager.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useCallback } from 'react'
2
  import { useTranslation } from 'react-i18next'
3
  import { useSettingsStore } from '@/stores/settings'
4
  import Button from '@/components/ui/Button'
@@ -97,6 +97,14 @@ export default function DocumentManager() {
97
  const showFileName = useSettingsStore.use.showFileName()
98
  const setShowFileName = useSettingsStore.use.setShowFileName()
99
 
 
 
 
 
 
 
 
 
100
  // Add pulse style to document
101
  useEffect(() => {
102
  const style = document.createElement('style')
@@ -110,8 +118,30 @@ export default function DocumentManager() {
110
  const fetchDocuments = useCallback(async () => {
111
  try {
112
  const docs = await getDocuments()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  if (docs && docs.statuses) {
114
- // compose all documents count
115
  const numDocuments = Object.values(docs.statuses).reduce(
116
  (acc, status) => acc + status.length,
117
  0
 
1
+ import { useState, useEffect, useCallback, useRef } from 'react'
2
  import { useTranslation } from 'react-i18next'
3
  import { useSettingsStore } from '@/stores/settings'
4
  import Button from '@/components/ui/Button'
 
97
  const showFileName = useSettingsStore.use.showFileName()
98
  const setShowFileName = useSettingsStore.use.setShowFileName()
99
 
100
+ // Store previous status counts
101
+ const prevStatusCounts = useRef({
102
+ processed: 0,
103
+ processing: 0,
104
+ pending: 0,
105
+ failed: 0
106
+ })
107
+
108
  // Add pulse style to document
109
  useEffect(() => {
110
  const style = document.createElement('style')
 
118
  const fetchDocuments = useCallback(async () => {
119
  try {
120
  const docs = await getDocuments()
121
+
122
+ // Get new status counts (treat null as all zeros)
123
+ const newStatusCounts = {
124
+ processed: docs?.statuses?.processed?.length || 0,
125
+ processing: docs?.statuses?.processing?.length || 0,
126
+ pending: docs?.statuses?.pending?.length || 0,
127
+ failed: docs?.statuses?.failed?.length || 0
128
+ }
129
+
130
+ // Check if any status count has changed
131
+ const hasStatusCountChange = (Object.keys(newStatusCounts) as Array<keyof typeof newStatusCounts>).some(
132
+ status => newStatusCounts[status] !== prevStatusCounts.current[status]
133
+ )
134
+
135
+ // Trigger health check if changes detected
136
+ if (hasStatusCountChange) {
137
+ useBackendState.getState().check()
138
+ }
139
+
140
+ // Update previous status counts
141
+ prevStatusCounts.current = newStatusCounts
142
+
143
+ // Update docs state
144
  if (docs && docs.statuses) {
 
145
  const numDocuments = Object.values(docs.statuses).reduce(
146
  (acc, status) => acc + status.length,
147
  0