Merge pull request #1992 from danielaskdd/doc-list-refresh

Fix: Preserve Document List Pagination During Pipeline Status Changes
This commit is contained in:
Daniel.y 2025-08-21 23:14:08 +08:00 committed by GitHub
commit dce678642a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 164 additions and 122 deletions

View file

@ -1 +1 @@
__api_version__ = "0205"
__api_version__ = "0206"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
import{j as o,Y as td,O as fg,k as dg,u as ad,Z as mg,c as hg,l as gg,g as pg,S as yg,T as vg,n as bg,m as nd,o as Sg,p as Tg,$ as ud,a0 as id,a1 as cd,a2 as xg}from"./ui-vendor-CeCm8EER.js";import{d as Ag,h as Dg,r as E,u as sd,H as Ng,i as Eg,j as kf}from"./react-vendor-DEwriMA6.js";import{N as we,c as Ve,ad as od,u as Bl,M as sl,ae as rd,af as fd,I as us,B as Cn,D as Mg,l as zg,m as Cg,n as Og,o as _g,ag as Rg,ah as jg,ai as Ug,aj as Hg,ak as ql,al as dd,am as ss,an as is,a0 as Lg,a1 as qg,a2 as Bg,a3 as Gg,ao as Yg,ap as Xg,aq as md,ar as wg,as as hd,at as Vg,au as gd,d as Qg,R as Kg,V as Zg,g as En,av as kg,aw as Jg,ax as Fg}from"./feature-graph-C6IuADHZ.js";import{S as Jf,a as Ff,b as Pf,c as $f,e as rt,D as Pg}from"./feature-documents-BSJWpkhB.js";import{R as $g}from"./feature-retrieval-kyTSZozC.js";import{i as cs}from"./utils-vendor-BysuhMZA.js";import"./graph-vendor-B-X5JegA.js";import"./mermaid-vendor-CAxUo7Zk.js";import"./markdown-vendor-DmIvJdn7.js";(function(){const y=document.createElement("link").relList;if(y&&y.supports&&y.supports("modulepreload"))return;for(const N of document.querySelectorAll('link[rel="modulepreload"]'))d(N);new MutationObserver(N=>{for(const _ of N)if(_.type==="childList")for(const H of _.addedNodes)H.tagName==="LINK"&&H.rel==="modulepreload"&&d(H)}).observe(document,{childList:!0,subtree:!0});function x(N){const _={};return N.integrity&&(_.integrity=N.integrity),N.referrerPolicy&&(_.referrerPolicy=N.referrerPolicy),N.crossOrigin==="use-credentials"?_.credentials="include":N.crossOrigin==="anonymous"?_.credentials="omit":_.credentials="same-origin",_}function d(N){if(N.ep)return;N.ep=!0;const _=x(N);fetch(N.href,_)}})();var ts={exports:{}},Mn={},as={exports:{}},ns={};/**
import{j as o,Y as td,O as fg,k as dg,u as ad,Z as mg,c as hg,l as gg,g as pg,S as yg,T as vg,n as bg,m as nd,o as Sg,p as Tg,$ as ud,a0 as id,a1 as cd,a2 as xg}from"./ui-vendor-CeCm8EER.js";import{d as Ag,h as Dg,r as E,u as sd,H as Ng,i as Eg,j as kf}from"./react-vendor-DEwriMA6.js";import{N as we,c as Ve,ad as od,u as Bl,M as sl,ae as rd,af as fd,I as us,B as Cn,D as Mg,l as zg,m as Cg,n as Og,o as _g,ag as Rg,ah as jg,ai as Ug,aj as Hg,ak as ql,al as dd,am as ss,an as is,a0 as Lg,a1 as qg,a2 as Bg,a3 as Gg,ao as Yg,ap as Xg,aq as md,ar as wg,as as hd,at as Vg,au as gd,d as Qg,R as Kg,V as Zg,g as En,av as kg,aw as Jg,ax as Fg}from"./feature-graph-C6IuADHZ.js";import{S as Jf,a as Ff,b as Pf,c as $f,e as rt,D as Pg}from"./feature-documents-Di_Wt0BY.js";import{R as $g}from"./feature-retrieval-DVuOAaIQ.js";import{i as cs}from"./utils-vendor-BysuhMZA.js";import"./graph-vendor-B-X5JegA.js";import"./mermaid-vendor-CAxUo7Zk.js";import"./markdown-vendor-DmIvJdn7.js";(function(){const y=document.createElement("link").relList;if(y&&y.supports&&y.supports("modulepreload"))return;for(const N of document.querySelectorAll('link[rel="modulepreload"]'))d(N);new MutationObserver(N=>{for(const _ of N)if(_.type==="childList")for(const H of _.addedNodes)H.tagName==="LINK"&&H.rel==="modulepreload"&&d(H)}).observe(document,{childList:!0,subtree:!0});function x(N){const _={};return N.integrity&&(_.integrity=N.integrity),N.referrerPolicy&&(_.referrerPolicy=N.referrerPolicy),N.crossOrigin==="use-credentials"?_.credentials="include":N.crossOrigin==="anonymous"?_.credentials="omit":_.credentials="same-origin",_}function d(N){if(N.ep)return;N.ep=!0;const _=x(N);fetch(N.href,_)}})();var ts={exports:{}},Mn={},as={exports:{}},ns={};/**
* @license React
* scheduler.production.js
*

View file

@ -8,16 +8,16 @@
<link rel="icon" type="image/png" href="favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-Ctn6Ym96.js"></script>
<script type="module" crossorigin src="/webui/assets/index-B90LgL3h.js"></script>
<link rel="modulepreload" crossorigin href="/webui/assets/react-vendor-DEwriMA6.js">
<link rel="modulepreload" crossorigin href="/webui/assets/ui-vendor-CeCm8EER.js">
<link rel="modulepreload" crossorigin href="/webui/assets/graph-vendor-B-X5JegA.js">
<link rel="modulepreload" crossorigin href="/webui/assets/utils-vendor-BysuhMZA.js">
<link rel="modulepreload" crossorigin href="/webui/assets/feature-graph-C6IuADHZ.js">
<link rel="modulepreload" crossorigin href="/webui/assets/feature-documents-BSJWpkhB.js">
<link rel="modulepreload" crossorigin href="/webui/assets/feature-documents-Di_Wt0BY.js">
<link rel="modulepreload" crossorigin href="/webui/assets/mermaid-vendor-CAxUo7Zk.js">
<link rel="modulepreload" crossorigin href="/webui/assets/markdown-vendor-DmIvJdn7.js">
<link rel="modulepreload" crossorigin href="/webui/assets/feature-retrieval-kyTSZozC.js">
<link rel="modulepreload" crossorigin href="/webui/assets/feature-retrieval-DVuOAaIQ.js">
<link rel="stylesheet" crossorigin href="/webui/assets/feature-graph-BipNuM18.css">
<link rel="stylesheet" crossorigin href="/webui/assets/index-CafJWW1u.css">
</head>

View file

@ -469,22 +469,42 @@ export default function DocumentManager() {
};
}, [docs]);
// New paginated data fetching function
const fetchPaginatedDocuments = useCallback(async (
page: number,
pageSize: number,
statusFilter: StatusFilter
// Utility function to update component state
const updateComponentState = useCallback((response: any) => {
setPagination(response.pagination);
setCurrentPageDocs(response.documents);
setStatusCounts(response.status_counts);
// Update legacy docs state for backward compatibility
const legacyDocs: DocsStatusesResponse = {
statuses: {
processed: response.documents.filter((doc: DocStatusResponse) => doc.status === 'processed'),
processing: response.documents.filter((doc: DocStatusResponse) => doc.status === 'processing'),
pending: response.documents.filter((doc: DocStatusResponse) => doc.status === 'pending'),
failed: response.documents.filter((doc: DocStatusResponse) => doc.status === 'failed')
}
};
setDocs(response.pagination.total_count > 0 ? legacyDocs : null);
}, []);
// Intelligent refresh function: handles all boundary cases
const handleIntelligentRefresh = useCallback(async (
targetPage?: number, // Optional target page, defaults to current page
resetToFirst?: boolean // Whether to force reset to first page
) => {
try {
if (!isMountedRef.current) return;
setIsRefreshing(true);
// Prepare request parameters
// Determine target page
const pageToFetch = resetToFirst ? 1 : (targetPage || pagination.page);
const request: DocumentsRequest = {
status_filter: statusFilter === 'all' ? null : statusFilter,
page,
page_size: pageSize,
page: pageToFetch,
page_size: pagination.page_size,
sort_field: sortField,
sort_direction: sortDirection
};
@ -493,27 +513,35 @@ export default function DocumentManager() {
if (!isMountedRef.current) return;
// Update pagination state
setPagination(response.pagination);
setCurrentPageDocs(response.documents);
setStatusCounts(response.status_counts);
// Boundary case handling: if target page has no data but total count > 0
if (response.documents.length === 0 && response.pagination.total_count > 0) {
// Calculate last page
const lastPage = Math.max(1, response.pagination.total_pages);
// Update legacy docs state for backward compatibility
const legacyDocs: DocsStatusesResponse = {
statuses: {
processed: response.documents.filter(doc => doc.status === 'processed'),
processing: response.documents.filter(doc => doc.status === 'processing'),
pending: response.documents.filter(doc => doc.status === 'pending'),
failed: response.documents.filter(doc => doc.status === 'failed')
if (pageToFetch !== lastPage) {
// Re-request last page
const lastPageRequest: DocumentsRequest = {
...request,
page: lastPage
};
const lastPageResponse = await getDocumentsPaginated(lastPageRequest);
if (!isMountedRef.current) return;
// Update page state to last page
setPageByStatus(prev => ({ ...prev, [statusFilter]: lastPage }));
updateComponentState(lastPageResponse);
return;
}
};
if (response.pagination.total_count > 0) {
setDocs(legacyDocs);
} else {
setDocs(null);
}
// Normal case: update state
if (pageToFetch !== pagination.page) {
setPageByStatus(prev => ({ ...prev, [statusFilter]: pageToFetch }));
}
updateComponentState(response);
} catch (err) {
if (isMountedRef.current) {
toast.error(t('documentPanel.documentManager.errors.loadFailed', { error: errorMessage(err) }));
@ -523,7 +551,20 @@ export default function DocumentManager() {
setIsRefreshing(false);
}
}
}, [sortField, sortDirection, t]);
}, [statusFilter, pagination.page, pagination.page_size, sortField, sortDirection, t, updateComponentState]);
// New paginated data fetching function
const fetchPaginatedDocuments = useCallback(async (
page: number,
pageSize: number,
_statusFilter: StatusFilter // eslint-disable-line @typescript-eslint/no-unused-vars
) => {
// Update pagination state
setPagination(prev => ({ ...prev, page, page_size: pageSize }));
// Use intelligent refresh
await handleIntelligentRefresh(page);
}, [handleIntelligentRefresh]);
// Legacy fetchDocuments function for backward compatibility
const fetchDocuments = useCallback(async () => {
@ -678,9 +719,10 @@ export default function DocumentManager() {
if (prevPipelineBusyRef.current !== undefined && prevPipelineBusyRef.current !== pipelineBusy) {
// pipelineBusy state has changed, trigger immediate refresh
if (currentTab === 'documents' && health && isMountedRef.current) {
handleManualRefresh();
// Use intelligent refresh to preserve current page
handleIntelligentRefresh();
// Reset polling timer after manual refresh
// Reset polling timer after intelligent refresh
const hasActiveDocuments = (statusCounts.processing || 0) > 0 || (statusCounts.pending || 0) > 0;
const pollingInterval = hasActiveDocuments ? 5000 : 30000;
startPollingInterval(pollingInterval);
@ -688,7 +730,7 @@ export default function DocumentManager() {
}
// Update the previous state
prevPipelineBusyRef.current = pipelineBusy;
}, [pipelineBusy, currentTab, health, handleManualRefresh, statusCounts.processing, statusCounts.pending, startPollingInterval]);
}, [pipelineBusy, currentTab, health, handleIntelligentRefresh, statusCounts.processing, statusCounts.pending, startPollingInterval]);
// Set up intelligent polling with dynamic interval based on document status
useEffect(() => {