From 9d558bb1e54b132696c7a16f573864b7d61bfe18 Mon Sep 17 00:00:00 2001 From: ByteExceptionM Date: Wed, 6 May 2026 23:36:57 +0200 Subject: [PATCH] perf: prefetch collections so ObjectId lookup menu opens instantly --- .../src/features/collection/DocumentTable.tsx | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/features/collection/DocumentTable.tsx b/src/renderer/src/features/collection/DocumentTable.tsx index c93dd40..fe8e330 100644 --- a/src/renderer/src/features/collection/DocumentTable.tsx +++ b/src/renderer/src/features/collection/DocumentTable.tsx @@ -79,10 +79,14 @@ export function DocumentTable({ const lastClickedIdRef = useRef(null) const openTab = useTabsStore((s) => s.open) + // Prefetched in the background as soon as the table mounts so the + // ObjectId-lookup submenu (right-click on an ObjectId cell) doesn't have to + // wait on a fresh `listCollections` round-trip. listCollections with + // `nameOnly: true` is cheap, and the cache is shared across tabs of the + // same DB. const collectionsQuery = useQuery({ queryKey: queryKeys.collections(connectionId, db), - queryFn: () => api.collections.list({ connectionId, db }), - enabled: activeLookup?.ref.kind === 'oid' + queryFn: () => api.collections.list({ connectionId, db }) }) /** User-set widths; auto-estimated widths fill in for the rest. */ @@ -474,17 +478,23 @@ export function DocumentTable({ Lookup ObjectId in… - {collectionsQuery.isLoading && ( - - - Loading… - - )} {(() => { - const others = (collectionsQuery.data ?? []).filter( - (c) => c.name !== coll - ) - if (collectionsQuery.isLoading) return null + if (collectionsQuery.isPending) { + return ( + + + Loading… + + ) + } + if (collectionsQuery.isError) { + return ( + + Failed to load collections + + ) + } + const others = collectionsQuery.data.filter((c) => c.name !== coll) if (others.length === 0) { return ( No other collections