fix(presto): optimize metadata completion
This commit is contained in:
1 parent
f5f6bc0b43
commit
95e3cb6571
9 files changed
+528
-37
No files matched your search
@@ -83,4 +83,33 @@ describe("connectionStore completion assistant", () => {
|
||||
expect(listTables).toHaveBeenCalledWith("pg-1", "app", "public", "acc", 20);
|
||||
expect(tables).toEqual([{ name: "accounts", schema: "public", type: "table" }]);
|
||||
});
|
||||
|
||||
it("keeps schema-qualified local table completion scoped to the selected schema", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockRejectedValue(new Error("assistant unavailable"));
|
||||
const listTables = vi.fn(async (_connectionId: string, _database: string, schema: string, filter: string) => {
|
||||
if (schema === "dim_game_base" && filter === "dim") {
|
||||
return [{ name: "dim_game", table_type: "BASE TABLE", comment: null }];
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
vi.doMock("@/lib/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
listSchemas: vi.fn().mockResolvedValue(["dim_game_base", "dws_game_sdk_base"]),
|
||||
listTables,
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [postgresConnection()];
|
||||
store.connectedIds.add("pg-1");
|
||||
|
||||
const dimTables = await store.listCompletionTables("pg-1", "app", "dim", 20, "dim_game_base");
|
||||
const dwsTables = store.lookupLocalCompletionTables("pg-1", "app", "d", 20, "dws_game_sdk_base");
|
||||
|
||||
expect(dimTables).toEqual([{ name: "dim_game", schema: "dim_game_base", type: "table" }]);
|
||||
expect(dwsTables).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -2966,7 +2966,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
function lookupLocalCompletionTables(connectionId: string, database: string, filter = "", limit?: number, schema?: string): SqlCompletionTable[] {
|
||||
const allScopes = [...completionTableIndex.entries()].filter(([key]) => key.startsWith(`${connectionId}:${database}:`)).map(([, entry]) => entry);
|
||||
const preferred = schema ? completionTableIndex.get(completionScopeKey(connectionId, database, schema)) : undefined;
|
||||
const scopes = preferred ? [preferred, ...allScopes.filter((entry) => entry !== preferred)] : allScopes;
|
||||
const scopes = schema ? (preferred ? [preferred] : []) : allScopes;
|
||||
const treeTables = completionTablesFromTree(treeNodes.value, connectionId, database, schema);
|
||||
const ranked = scopes
|
||||
.flatMap((entry) => entry?.tables ?? [])
|
||||
@@ -2980,7 +2980,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
function lookupLocalCompletionObjects(connectionId: string, database: string, filter = "", limit?: number, schema?: string): SqlCompletionObject[] {
|
||||
const allScopes = [...completionObjectIndex.entries()].filter(([key]) => key.startsWith(`${connectionId}:${database}:`)).map(([, entry]) => entry);
|
||||
const preferred = schema ? completionObjectIndex.get(completionScopeKey(connectionId, database, schema)) : undefined;
|
||||
const scopes = preferred ? [preferred, ...allScopes.filter((entry) => entry !== preferred)] : allScopes;
|
||||
const scopes = schema ? (preferred ? [preferred] : []) : allScopes;
|
||||
const ranked = scopes
|
||||
.flatMap((entry) => entry?.objects ?? [])
|
||||
.map((object) => ({ object, score: objectMatchScore(object, filter, schema) }))
|
||||
|
||||
Reference in new issue
Block a user