Fix parsing log display of infinity (#17479)

This commit is contained in:
Yingfeng
2026-07-28 23:04:56 +08:00
committed by GitHub
parent e91da6b214
commit 9460e6ba03
3 changed files with 51 additions and 36 deletions

View File

@@ -256,15 +256,20 @@ export const useFetchDocumentList = (loop = true) => {
};
};
export const useFetchDocumentsByIds = (ids: string[]) => {
export const useFetchDocumentsByIds = (
ids: string[],
options?: { enabled?: boolean; refetchInterval?: number | false },
) => {
const { id: datasetId } = useParams();
const { enabled, refetchInterval } = options ?? {};
const { data, isFetching: loading } = useQuery<{
docs: IDocumentInfo[];
total: number;
}>({
queryKey: DocumentKeys.byIds(ids),
enabled: ids.length > 0 && !!datasetId,
enabled: (enabled ?? true) && ids.length > 0 && !!datasetId,
refetchInterval,
initialData: { docs: [], total: 0 },
queryFn: async () => {
const ret = await listDocument(

View File

@@ -5,37 +5,51 @@ import { formatBytes } from '@/utils/file-util';
import { useCallback, useMemo, useState } from 'react';
import { ILogInfo } from '../process-log-modal';
import { RunningStatus } from './constant';
import { useFetchDocumentsByIds } from '@/hooks/use-document-request';
const PollIntervalMs = 5000;
export const useShowLog = (documents: IDocumentInfo[]) => {
const { showModal, hideModal, visible } = useSetModalState();
const [record, setRecord] = useState<IDocumentInfo>();
// When the modal is visible, poll the document directly by ID so progress_msg
// updates (e.g. "Indexing done") are captured even if the parent list no longer
// polls (isLoop became false before the final message) or the record fell off
// the current paginated page.
const { documents: liveDocs } = useFetchDocumentsByIds(
record?.id ? [record.id] : [],
{ enabled: visible, refetchInterval: PollIntervalMs },
);
const liveDoc = liveDocs?.[0];
const logInfo = useMemo(() => {
const findRecord = documents.find(
const source = liveDoc ?? documents.find(
(item: IDocumentInfo) => item.id === record?.id,
);
) ?? record;
let log: ILogInfo = {
taskId: record?.id,
fileName: record?.name || '-',
details: record?.progress_msg || '-',
taskId: source?.id,
fileName: source?.name || '-',
details: source?.progress_msg || '-',
};
if (findRecord) {
if (source) {
log = {
fileType: findRecord?.suffix,
uploadedBy: findRecord?.nickname,
fileName: findRecord?.name,
uploadDate: formatDate(findRecord.create_date),
fileSize: formatBytes(findRecord.size || 0),
processBeginAt: formatDate(findRecord.process_begin_at),
chunkNumber: findRecord.chunk_count,
fileType: source?.suffix,
uploadedBy: source?.nickname,
fileName: source?.name,
uploadDate: formatDate(source.create_date),
fileSize: formatBytes(source.size || 0),
processBeginAt: formatDate(source.process_begin_at),
chunkNumber: source.chunk_count,
duration: formatSecondsToHumanReadable(
findRecord.process_duration || 0,
source.process_duration || 0,
),
status: findRecord.run as RunningStatus,
details: findRecord.progress_msg,
status: source.run as RunningStatus,
details: source.progress_msg,
};
}
return log;
}, [record, documents]);
}, [record, documents, liveDoc]);
const showLog = useCallback(
(data: IDocumentInfo) => {
setRecord(data);