Skip to content

fix: disable prefetches for audits table #11040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/src/api/queries/audits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export function paginatedAudits(
q: payload,
});
},
prefetch: false,
};
}
12 changes: 12 additions & 0 deletions site/src/hooks/usePaginatedQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export type UsePaginatedQueryOptions<
* closest valid page.
*/
onInvalidPageChange?: (params: InvalidPageParams) => void;

/**
* Defaults to true. Allows you to disable prefetches for pages where making
* a request is very expensive.
*/
prefetch?: boolean;
};

/**
Expand Down Expand Up @@ -98,6 +104,7 @@ export function usePaginatedQuery<
onInvalidPageChange,
searchParams: outerSearchParams,
queryFn: outerQueryFn,
prefetch = true,
...extraOptions
} = options;

Expand Down Expand Up @@ -148,7 +155,12 @@ export function usePaginatedQuery<

const queryClient = useQueryClient();
const prefetchPage = useEffectEvent((newPage: number) => {
if (!prefetch) {
return;
}

const options = getQueryOptionsFromPage(newPage);

return queryClient.prefetchQuery(options);
});

Expand Down