mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
feat(app): 1s staleTime to avoid sending repeated requests (#607)
This commit is contained in:
parent
ebc25e45d3
commit
c331ada086
10 changed files with 4 additions and 14 deletions
|
@ -20,7 +20,6 @@ export function useTags<T = Tag[]>({
|
|||
enabled = true,
|
||||
}: { select?: (tags: Tag[]) => T; enabled?: boolean } = {}) {
|
||||
return useQuery(tagKeys.all, () => getTags(), {
|
||||
staleTime: 50,
|
||||
select,
|
||||
enabled,
|
||||
...withError('Failed to retrieve tags'),
|
||||
|
|
|
@ -12,10 +12,9 @@ interface CurrentUserResponse extends User {
|
|||
forceChangePassword: boolean;
|
||||
}
|
||||
|
||||
export function useLoadCurrentUser({ staleTime }: { staleTime?: number } = {}) {
|
||||
export function useLoadCurrentUser() {
|
||||
return useQuery(userQueryKeys.me(), () => getCurrentUser(), {
|
||||
...withError('Unable to retrieve user details'),
|
||||
staleTime,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,9 @@ import { User, UserId } from '../types';
|
|||
|
||||
import { userQueryKeys } from './queryKeys';
|
||||
|
||||
export function useUser(
|
||||
id: UserId,
|
||||
{ staleTime }: { staleTime?: number } = {}
|
||||
) {
|
||||
export function useUser(id: UserId) {
|
||||
return useQuery(userQueryKeys.user(id), () => getUser(id), {
|
||||
...withError('Unable to retrieve user details'),
|
||||
staleTime,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ export function createQueryClient() {
|
|||
defaultOptions: {
|
||||
queries: {
|
||||
networkMode: 'offlineFirst',
|
||||
staleTime: 1000, // 1s stale time by default
|
||||
},
|
||||
},
|
||||
mutationCache: new MutationCache({
|
||||
|
|
|
@ -83,7 +83,6 @@ export function useDeleteHelmRepositoriesMutation() {
|
|||
|
||||
export function useHelmRepositories(userId: number) {
|
||||
return useQuery(['helmrepositories'], () => getHelmRepositories(userId), {
|
||||
staleTime: 20,
|
||||
...withError('Unable to retrieve Helm repositories'),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ export function useGroup<T = EnvironmentGroup>(
|
|||
return getGroup(groupId);
|
||||
},
|
||||
{
|
||||
staleTime: 50,
|
||||
select,
|
||||
enabled: groupId !== undefined,
|
||||
...withGlobalError('Failed loading group'),
|
||||
|
|
|
@ -27,7 +27,6 @@ export function useEnvironment<T = Environment>(
|
|||
{
|
||||
select,
|
||||
...withError('Failed loading environment'),
|
||||
staleTime: 50,
|
||||
enabled: !!environmentId,
|
||||
refetchInterval() {
|
||||
return options?.autoRefreshRate ?? false;
|
||||
|
|
|
@ -20,7 +20,7 @@ interface Params {
|
|||
export function useTagDetails<T = RepositoryTagViewModel>(
|
||||
params: Params,
|
||||
{
|
||||
staleTime = 0,
|
||||
staleTime,
|
||||
select,
|
||||
}: { select?: (model: RepositoryTagViewModel) => T; staleTime?: number } = {}
|
||||
) {
|
||||
|
|
|
@ -19,7 +19,6 @@ export function useExperimentalSettings<T = ExperimentalFeaturesSettings>(
|
|||
return useQuery(queryKeys.experimental(), getExperimentalSettings, {
|
||||
select,
|
||||
enabled,
|
||||
staleTime: 50,
|
||||
...withError('Unable to retrieve experimental settings'),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ export function useSettings<T = Settings>(
|
|||
return useQuery(queryKeys.base(), getSettings, {
|
||||
select,
|
||||
enabled,
|
||||
staleTime: 50,
|
||||
...withError('Unable to retrieve settings'),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue