mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
fix: increase default staleTime for paginated data (#11041)
* fix: update default staleTime for paginated data * fix: swap cacheTime for staleTime in app-wide query client * fix: revert cacheTime change * fix: update debug limit * fix: apply staleTime to prefetches * refactor: cleanup code
This commit is contained in:
@@ -105,6 +105,7 @@ export function usePaginatedQuery<
|
||||
searchParams: outerSearchParams,
|
||||
queryFn: outerQueryFn,
|
||||
prefetch = true,
|
||||
staleTime = 60 * 1000, // One minute
|
||||
...extraOptions
|
||||
} = options;
|
||||
|
||||
@@ -115,7 +116,8 @@ export function usePaginatedQuery<
|
||||
const currentPage = parsePage(searchParams);
|
||||
const currentPageOffset = (currentPage - 1) * limit;
|
||||
|
||||
const getQueryOptionsFromPage = (pageNumber: number) => {
|
||||
type Options = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
||||
const getQueryOptionsFromPage = (pageNumber: number): Options => {
|
||||
const pageParams: QueryPageParams = {
|
||||
pageNumber,
|
||||
limit,
|
||||
@@ -124,13 +126,13 @@ export function usePaginatedQuery<
|
||||
};
|
||||
|
||||
const payload = queryPayload?.(pageParams) as RuntimePayload<TQueryPayload>;
|
||||
|
||||
return {
|
||||
staleTime,
|
||||
queryKey: queryKey({ ...pageParams, payload }),
|
||||
queryFn: (context: QueryFunctionContext<TQueryKey>) => {
|
||||
return outerQueryFn({ ...context, ...pageParams, payload });
|
||||
},
|
||||
} as const;
|
||||
};
|
||||
};
|
||||
|
||||
// Not using infinite query right now because that requires a fair bit of list
|
||||
@@ -160,7 +162,6 @@ export function usePaginatedQuery<
|
||||
}
|
||||
|
||||
const options = getQueryOptionsFromPage(newPage);
|
||||
|
||||
return queryClient.prefetchQuery(options);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user