Fix performance related to having 100s of requests (#123)

This commit is contained in:
Gregory Schier
2024-10-08 15:16:57 -06:00
committed by GitHub
parent 4b7712df80
commit c7eccddac9
34 changed files with 456 additions and 423 deletions

View File

@@ -1,24 +1,8 @@
import { useQuery } from '@tanstack/react-query';
import type { GrpcConnection } from '@yaakapp-internal/models';
import { invokeCmd } from '../lib/tauri';
import { atom, useAtomValue } from 'jotai/index';
export function grpcConnectionsQueryKey({ requestId }: { requestId: string }) {
return ['grpc_connections', { requestId }];
}
export const grpcConnectionsAtom = atom<GrpcConnection[]>([]);
export function useGrpcConnections(requestId: string | null) {
return (
useQuery<GrpcConnection[]>({
enabled: requestId !== null,
initialData: [],
queryKey: grpcConnectionsQueryKey({ requestId: requestId ?? 'n/a' }),
queryFn: async () => {
if (requestId == null) return [];
return (await invokeCmd('cmd_list_grpc_connections', {
requestId,
limit: 200,
})) as GrpcConnection[];
},
}).data ?? []
);
export function useGrpcConnections() {
return useAtomValue(grpcConnectionsAtom);
}