fix: do not cache while watching during manual updates

This commit is contained in:
jialin
2026-02-13 19:32:59 +08:00
parent 88aafbaf7b
commit 511297ed11
8 changed files with 28 additions and 14 deletions
+4 -3
View File
@@ -112,7 +112,6 @@ export default function useTableFetch<T>(
const params = {
..._.pickBy(query || queryParams, (val: any) => !!val)
};
chunkRequestRef.current?.current?.cancel?.();
axiosTokenRef.current?.cancel?.('CANCEL_PREVIOUS_REQUEST');
axiosTokenRef.current = createAxiosToken();
const res = await fetchAPI(params, {
@@ -187,8 +186,8 @@ export default function useTableFetch<T>(
}
};
// @ts-ignore
const debounceFetchData = _.debounce(() => fetchData(), 300);
// @ts-ignore for watch mode
const debounceFetchData = _.debounce(() => fetchData({}, true), 1000);
const { updateChunkedList, cacheDataListRef } = useUpdateChunkedList({
events: events,
@@ -269,6 +268,8 @@ export default function useTableFetch<T>(
paginate?: boolean;
}
) => {
// cancel previous chunk request so that we can create a new one with updated params
chunkRequestRef.current?.current?.cancel?.();
const newQueryParams = { ...queryParams, ...params };
setQueryParams(newQueryParams);
const res = await fetchData({ query: newQueryParams });
+4 -6
View File
@@ -71,9 +71,9 @@ export function useUpdateChunkedList(options: {
(sItem: any) => sItem.id === item.id
);
const updateItem = { ...item };
if (updateIndex === -1) {
if (updateIndex === -1 && !triggerAt?.current) {
acc.push(updateItem);
} else {
} else if (!triggerAt?.current) {
cacheDataListRef.current[updateIndex] = updateItem;
}
@@ -116,8 +116,6 @@ export function useUpdateChunkedList(options: {
deletedIds: [...deletedIdsRef.current]
});
console.log('deletedList:', deletedList);
options.onDelete?.(deletedList);
}
@@ -135,9 +133,9 @@ export function useUpdateChunkedList(options: {
updateItem,
...cacheDataListRef.current.slice(0, limit - 1)
];
if (options.onCreate && triggerAt?.current) {
if (options.onUpdate && triggerAt?.current) {
if (Date.parse(item.created_at) >= triggerAt.current) {
options.onCreate?.([updateItem]);
options.onUpdate?.([updateItem]);
}
}
}