// Admin count query - separate optimized query just for counting
const { data: adminData } = useQuery<UsersResponse>({
queryKey: ["users-admin-count"],
queryFn: async () => {
try {
const data = await client.admin.listUsers(
{
query: {
limit: 1, // We only need the total count, not the actual users
filterField: "role",
filterOperator: "eq",
filterValue: "admin"
}
},
{
throw: true,
},
);
return data as UsersResponse;
} catch (error: any) {
console.error("Failed to fetch admin count:", error);
return { users: [], total: 0 } as UsersResponse;
}
},
// Keep the count cached for longer since it doesn't change as frequently
staleTime: 5 * 60 * 1000, // 5 minutes
});
// Admin count query - separate optimized query just for counting
const { data: adminData } = useQuery<UsersResponse>({
queryKey: ["users-admin-count"],
queryFn: async () => {
try {
const data = await client.admin.listUsers(
{
query: {
limit: 1, // We only need the total count, not the actual users
filterField: "role",
filterOperator: "eq",
filterValue: "admin"
}
},
{
throw: true,
},
);
return data as UsersResponse;
} catch (error: any) {
console.error("Failed to fetch admin count:", error);
return { users: [], total: 0 } as UsersResponse;
}
},
// Keep the count cached for longer since it doesn't change as frequently
staleTime: 5 * 60 * 1000, // 5 minutes
});