fix: too many requests after query change
This commit is contained in:
+11
-11
@@ -73,18 +73,18 @@ export default [
|
|||||||
selectedIcon: 'icon-audio-filled',
|
selectedIcon: 'icon-audio-filled',
|
||||||
defaultIcon: 'icon-audio1',
|
defaultIcon: 'icon-audio1',
|
||||||
component: './playground/speech'
|
component: './playground/speech'
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'video',
|
|
||||||
title: 'Video',
|
|
||||||
path: '/playground/video',
|
|
||||||
key: 'video',
|
|
||||||
icon: 'icon-video-outline',
|
|
||||||
hideInMenu: false,
|
|
||||||
selectedIcon: 'icon-video-filled02',
|
|
||||||
defaultIcon: 'icon-video-outline',
|
|
||||||
component: './playground/video'
|
|
||||||
}
|
}
|
||||||
|
// {
|
||||||
|
// name: 'video',
|
||||||
|
// title: 'Video',
|
||||||
|
// path: '/playground/video',
|
||||||
|
// key: 'video',
|
||||||
|
// icon: 'icon-video-outline',
|
||||||
|
// hideInMenu: false,
|
||||||
|
// selectedIcon: 'icon-video-filled02',
|
||||||
|
// defaultIcon: 'icon-video-outline',
|
||||||
|
// component: './playground/video'
|
||||||
|
// }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export default function useTableFetch<T>(
|
|||||||
const modalRef = useRef<any>(null);
|
const modalRef = useRef<any>(null);
|
||||||
const rowSelection = useTableRowSelection();
|
const rowSelection = useTableRowSelection();
|
||||||
const { sortOrder, handleMultiSortChange } = useTableMultiSort();
|
const { sortOrder, handleMultiSortChange } = useTableMultiSort();
|
||||||
|
const shouldUpdateRef = useRef(false);
|
||||||
|
const loadendRef = useRef(false);
|
||||||
|
|
||||||
// for skeleton loading
|
// for skeleton loading
|
||||||
const [extraStatus, setExtraStatus] = useState<Record<string, any>>({
|
const [extraStatus, setExtraStatus] = useState<Record<string, any>>({
|
||||||
@@ -150,6 +152,7 @@ export default function useTableFetch<T>(
|
|||||||
total: newRes.pagination.total,
|
total: newRes.pagination.total,
|
||||||
totalPage: newRes.pagination.totalPage
|
totalPage: newRes.pagination.totalPage
|
||||||
});
|
});
|
||||||
|
loadendRef.current = true;
|
||||||
if (isInfiniteScroll) {
|
if (isInfiniteScroll) {
|
||||||
setQueryParams(newParams);
|
setQueryParams(newParams);
|
||||||
}
|
}
|
||||||
@@ -165,6 +168,7 @@ export default function useTableFetch<T>(
|
|||||||
total: res.pagination.total,
|
total: res.pagination.total,
|
||||||
totalPage: res.pagination.totalPage
|
totalPage: res.pagination.totalPage
|
||||||
});
|
});
|
||||||
|
loadendRef.current = true;
|
||||||
if (isInfiniteScroll && query?.page) {
|
if (isInfiniteScroll && query?.page) {
|
||||||
setQueryParams({
|
setQueryParams({
|
||||||
...queryParams,
|
...queryParams,
|
||||||
@@ -180,6 +184,7 @@ export default function useTableFetch<T>(
|
|||||||
total: dataSource.total,
|
total: dataSource.total,
|
||||||
totalPage: dataSource.totalPage
|
totalPage: dataSource.totalPage
|
||||||
});
|
});
|
||||||
|
loadendRef.current = true;
|
||||||
} finally {
|
} finally {
|
||||||
debounceSetExtraStatus({
|
debounceSetExtraStatus({
|
||||||
firstLoad: false
|
firstLoad: false
|
||||||
@@ -190,24 +195,25 @@ export default function useTableFetch<T>(
|
|||||||
const debounceFetchData = _.debounce(fetchData, 300);
|
const debounceFetchData = _.debounce(fetchData, 300);
|
||||||
|
|
||||||
const updateHandler = (list: any) => {
|
const updateHandler = (list: any) => {
|
||||||
let shouldUpdate = false;
|
|
||||||
_.each(list, (data: any) => {
|
_.each(list, (data: any) => {
|
||||||
updateChunkedList(data);
|
updateChunkedList(data);
|
||||||
});
|
});
|
||||||
shouldUpdate = list.some(
|
shouldUpdateRef.current = list.some(
|
||||||
(data: any) =>
|
(data: any) =>
|
||||||
data.type === WatchEventType.DELETE ||
|
data.type === WatchEventType.DELETE ||
|
||||||
data.type === WatchEventType.CREATE
|
data.type === WatchEventType.CREATE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (shouldUpdate && updateManually && dataSource.loadend) {
|
if (shouldUpdateRef.current && updateManually && loadendRef.current) {
|
||||||
shouldUpdate = false;
|
shouldUpdateRef.current = false;
|
||||||
debounceFetchData();
|
debounceFetchData();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createModelsChunkRequest = async (params?: any) => {
|
const createModelsChunkRequest = async (params?: any) => {
|
||||||
if (!API || !watch) return;
|
if (!API || !watch) return;
|
||||||
|
shouldUpdateRef.current = false;
|
||||||
|
loadendRef.current = false;
|
||||||
chunkRequedtRef.current?.current?.cancel?.();
|
chunkRequedtRef.current?.current?.cancel?.();
|
||||||
try {
|
try {
|
||||||
const query = _.omit(params || queryParams, ['page', 'perPage']);
|
const query = _.omit(params || queryParams, ['page', 'perPage']);
|
||||||
@@ -241,6 +247,7 @@ export default function useTableFetch<T>(
|
|||||||
|
|
||||||
// for filters change
|
// for filters change
|
||||||
const handleQueryChange = (params: any) => {
|
const handleQueryChange = (params: any) => {
|
||||||
|
loadendRef.current = false;
|
||||||
setQueryParams({
|
setQueryParams({
|
||||||
...queryParams,
|
...queryParams,
|
||||||
...params
|
...params
|
||||||
|
|||||||
Reference in New Issue
Block a user