fix: Change the data in the dataset page to be obtained using the interface (#8726)

### What problem does this PR solve?

Change the data in the dataset page to be obtained using the interface,
and change the import to obtain all data every 15 seconds to obtain the
data of the current page every 5 seconds when parsing the existing file.
[#3221](https://github.com/infiniflow/ragflow/issues/3221)

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
chanx
2025-07-08 19:19:07 +08:00
committed by GitHub
parent 3fe143d84a
commit edb32b1304
17 changed files with 189 additions and 100 deletions

View File

@ -1,5 +1,8 @@
import { useHandleFilterSubmit } from '@/components/list-filter-bar/use-handle-filter-submit';
import { IDocumentInfo } from '@/interfaces/database/document';
import {
IDocumentInfo,
IDocumentInfoFilter,
} from '@/interfaces/database/document';
import {
IChangeParserConfigRequestBody,
IDocumentMetaRequestBody,
@ -10,7 +13,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useDebounce } from 'ahooks';
import { message } from 'antd';
import { get } from 'lodash';
import { useCallback } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { useParams } from 'umi';
import {
useGetPaginationWithRouter,
@ -30,7 +33,7 @@ export const enum DocumentApiAction {
SaveDocumentName = 'saveDocumentName',
SetDocumentParser = 'setDocumentParser',
SetDocumentMeta = 'setDocumentMeta',
FetchAllDocumentList = 'fetchAllDocumentList',
FetchDocumentFilter = 'fetchDocumentFilter',
CreateDocument = 'createDocument',
}
@ -81,6 +84,10 @@ export const useFetchDocumentList = () => {
const { id } = useParams();
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
const { filterValue, handleFilterSubmit } = useHandleFilterSubmit();
const [docs, setDocs] = useState<IDocumentInfo[]>([]);
const isLoop = useMemo(() => {
return docs.some((doc) => doc.run === '1');
}, [docs]);
const { data, isFetching: loading } = useQuery<{
docs: IDocumentInfo[];
@ -93,7 +100,7 @@ export const useFetchDocumentList = () => {
filterValue,
],
initialData: { docs: [], total: 0 },
// refetchInterval: 15000,
refetchInterval: isLoop ? 5000 : false,
enabled: !!knowledgeId || !!id,
queryFn: async () => {
const ret = await listDocument(
@ -104,7 +111,7 @@ export const useFetchDocumentList = () => {
page: pagination.current,
},
{
types: filterValue.type,
suffix: filterValue.type,
run_status: filterValue.run,
},
);
@ -118,7 +125,9 @@ export const useFetchDocumentList = () => {
};
},
});
useMemo(() => {
setDocs(data.docs);
}, [data.docs]);
const onInputChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
(e) => {
setPagination({ page: 1 });
@ -139,34 +148,48 @@ export const useFetchDocumentList = () => {
};
};
export function useFetchAllDocumentList() {
// get document filter
export const useGetDocumentFilter = (): {
filter: IDocumentInfoFilter;
onOpenChange: (open: boolean) => void;
} => {
const { knowledgeId } = useGetKnowledgeSearchParams();
const { searchString } = useHandleSearchChange();
const { id } = useParams();
const { data, isFetching: loading } = useQuery<{
docs: IDocumentInfo[];
total: number;
}>({
queryKey: [DocumentApiAction.FetchAllDocumentList],
initialData: { docs: [], total: 0 },
refetchInterval: 15000,
enabled: !!id,
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
const [open, setOpen] = useState<number>(0);
const { data } = useQuery({
queryKey: [
DocumentApiAction.FetchDocumentFilter,
debouncedSearchString,
knowledgeId,
open,
],
queryFn: async () => {
const ret = await listDocument({
kb_id: id,
const { data } = await kbService.documentFilter({
kb_id: knowledgeId || id,
keywords: debouncedSearchString,
});
if (ret.data.code === 0) {
return ret.data.data;
if (data.code === 0) {
return data.data;
}
return {
docs: [],
total: 0,
};
},
});
return { data, loading };
}
const handleOnpenChange = (e: boolean) => {
if (e) {
const currentOpen = open + 1;
setOpen(currentOpen);
}
};
return {
filter: data?.filter || {
run_status: {},
suffix: {},
},
onOpenChange: handleOnpenChange,
};
};
// update document status
export const useSetDocumentStatus = () => {
const queryClient = useQueryClient();
@ -200,6 +223,7 @@ export const useSetDocumentStatus = () => {
return { setDocumentStatus: mutateAsync, data, loading };
};
// This hook is used to run a document by its IDs
export const useRunDocument = () => {
const queryClient = useQueryClient();