From 4d2b60326d9c40ec605899c661f0af62a34c8dd8 Mon Sep 17 00:00:00 2001 From: zipg Date: Wed, 22 Jul 2026 15:14:36 +0800 Subject: [PATCH] fix(oracle): refresh DIP object tree cache --- .../connectionStore.metadataLoading.spec.ts | 92 +++++++++++++++++++ apps/desktop/src/stores/connectionStore.ts | 4 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts index dc0c1e6b70..77ee0688b5 100644 --- a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts +++ b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts @@ -37,6 +37,19 @@ function mysqlConnection(): ConnectionConfig { } as ConnectionConfig; } +function oracleConnection(): ConnectionConfig { + return { + id: "oracle-1", + name: "Oracle", + db_type: "oracle", + host: "127.0.0.1", + port: 1521, + username: "SYSTEM", + password: "", + database: "XE", + } as ConnectionConfig; +} + function procedure(name: string): ObjectInfo { return { name, @@ -212,6 +225,85 @@ describe("connectionStore metadata loading", () => { expect(schemaNode.children?.map((node) => node.label)).toEqual(["users"]); }); + it("bypasses Oracle object-group caches created before DIP visibility was fixed", async () => { + const listTables = vi.fn().mockResolvedValue([ + { name: "V_ONE", table_type: "VIEW", comment: null }, + { name: "V_TWO", table_type: "VIEW", comment: null }, + { name: "V_THREE", table_type: "VIEW", comment: null }, + ] satisfies TableInfo[]); + const legacyChildren: TreeNode[] = [ + { id: "oracle-1:XE:DIP:__views:DIP:V_ONE", label: "V_ONE", type: "view", connectionId: "oracle-1", database: "XE", schema: "DIP", isExpanded: false }, + { id: "oracle-1:XE:DIP:__views:DIP:V_TWO", label: "V_TWO", type: "view", connectionId: "oracle-1", database: "XE", schema: "DIP", isExpanded: false }, + ]; + const loadSchemaCache = vi.fn(async (key: string) => + key.endsWith(":objects-v5") + ? { + version: 2, + cachedAt: new Date().toISOString(), + children: legacyChildren, + } + : null, + ); + + vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false })); + vi.doMock("@/lib/backend/api", () => ({ + checkConnectionHealth: vi.fn().mockResolvedValue(undefined), + deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined), + listTables, + loadSchemaCache, + saveSchemaCache: vi.fn().mockResolvedValue(undefined), + saveConnections: vi.fn().mockResolvedValue(undefined), + saveSidebarLayout: vi.fn().mockResolvedValue(undefined), + })); + + const { useConnectionStore } = await import("@/stores/connectionStore"); + const { useSettingsStore } = await import("@/stores/settingsStore"); + const store = useConnectionStore(); + useSettingsStore().desktopSettings.sidebar_table_page_size = 200; + const connection = oracleConnection(); + const viewGroup: TreeNode = { + id: "oracle-1:XE:DIP:__views", + label: "tree.views", + type: "group-views", + connectionId: connection.id, + database: "XE", + schema: "DIP", + isExpanded: false, + children: [], + }; + store.connections = [connection]; + store.connectedIds.add(connection.id); + store.treeNodes = [ + { + id: connection.id, + label: connection.name, + type: "connection", + connectionId: connection.id, + isExpanded: true, + children: [ + { + id: "oracle-1:XE:DIP", + label: "DIP", + type: "schema", + connectionId: connection.id, + database: "XE", + schema: "DIP", + isExpanded: true, + children: [viewGroup], + }, + ], + }, + ]; + + const storedViewGroup = store.treeNodes[0].children?.[0].children?.[0]; + expect(storedViewGroup?.type).toBe("group-views"); + await store.loadObjectGroupChildren(storedViewGroup!); + + expect(loadSchemaCache).toHaveBeenCalledWith("oracle-1:XE:DIP:group-views:objects-v6"); + expect(listTables).toHaveBeenCalledWith(connection.id, "XE", "DIP", undefined, 201, 0, ["VIEW"]); + expect(storedViewGroup?.children?.map((node) => node.label)).toEqual(["V_ONE", "V_THREE", "V_TWO"]); + }); + it("clears a stale connection error after a schema metadata retry succeeds", async () => { const listSchemaInfos = vi .fn() diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts index fdbf123d62..eaac7c1065 100644 --- a/apps/desktop/src/stores/connectionStore.ts +++ b/apps/desktop/src/stores/connectionStore.ts @@ -1124,7 +1124,9 @@ export const useConnectionStore = defineStore("connection", () => { } function objectGroupCacheKey(node: TreeNode): string { - return schemaCacheKey(node.connectionId || "", node.database || "", node.schema || "", node.type, "objects-v5"); + const config = node.connectionId ? getConfig(node.connectionId) : undefined; + const cacheVersion = config?.db_type === "oracle" ? "objects-v6" : "objects-v5"; + return schemaCacheKey(node.connectionId || "", node.database || "", node.schema || "", node.type, cacheVersion); } function metadataListDriverProfile(connectionId?: string): string | undefined {