2025-04-26 00:16:49 +08:00
|
|
|
import { RustApiError } from '@/api/buster_rest/errors';
|
2025-05-13 23:46:21 +08:00
|
|
|
import { queryKeys } from '@/api/query_keys';
|
2025-04-26 00:16:49 +08:00
|
|
|
import { QueryClient, queryOptions } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
export const isQueryStale = (
|
|
|
|
options: ReturnType<typeof queryOptions<any, RustApiError, any>>,
|
|
|
|
queryClient: QueryClient
|
|
|
|
): boolean => {
|
|
|
|
const queryState = queryClient.getQueryState(options.queryKey);
|
|
|
|
const updatedAt = queryState?.dataUpdatedAt;
|
|
|
|
const staleTime =
|
|
|
|
(options.staleTime as number) ||
|
|
|
|
(queryClient.getDefaultOptions().queries?.staleTime as number) ||
|
|
|
|
0;
|
|
|
|
const isStale = updatedAt ? Date.now() - updatedAt > staleTime : true;
|
|
|
|
|
|
|
|
return isStale;
|
|
|
|
};
|
2025-05-13 23:46:21 +08:00
|
|
|
|
|
|
|
export const hasOrganizationId = (queryClient: QueryClient): boolean => {
|
|
|
|
const organizationId = queryClient.getQueryData(queryKeys.userGetUserMyself.queryKey)
|
|
|
|
?.organizations?.[0]?.id;
|
|
|
|
return !!organizationId;
|
|
|
|
};
|