fix(completion): scoped table lookup, preserve casing, lower Oracle table-function boost
* fix: improve schema-qualified SQL completion * fix(completion): preserve casing in completion table cache key and relaxed filter --------- Co-authored-by: zipg <4047349+zipg@users.noreply.github.com> Co-authored-by: t8y2 <1156263951@qq.com>
This commit is contained in:
5 files changed
+51
-9
No files matched your search
@@ -121,6 +121,32 @@ describe("connectionStore completion assistant", () => {
|
||||
expect(dwsTables).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves table filter casing for assistant searches", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "TEST_USERS", kind: "table", schema: "SYSDBA" }],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
listSchemas: vi.fn().mockResolvedValue(["SYSDBA"]),
|
||||
listTables: vi.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [postgresConnection()];
|
||||
store.connectedIds.add("pg-1");
|
||||
|
||||
const tables = await store.listCompletionTables("pg-1", "app", "TEST_", 20, "SYSDBA");
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenCalledWith(expect.objectContaining({ mask: "TEST_", schema: "SYSDBA", parent_schema: "SYSDBA" }));
|
||||
expect(tables).toEqual([{ name: "TEST_USERS", schema: "SYSDBA", type: "table" }]);
|
||||
});
|
||||
|
||||
it("limits concurrent completion column metadata requests per connection database", async () => {
|
||||
const gates = [deferred<any[]>(), deferred<any[]>(), deferred<any[]>(), deferred<any[]>()];
|
||||
let activeColumns = 0;
|
||||
|
||||
@@ -3916,9 +3916,14 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
|
||||
async function listCompletionTables(connectionId: string, database: string, filter = "", limit?: number, schema?: string): Promise<SqlCompletionTable[]> {
|
||||
const normalizedFilter = filter.trim().toLowerCase();
|
||||
const relaxedFilter = relaxedCompletionTableFilter(normalizedFilter);
|
||||
const cacheKey = `${connectionId}:${database}:${normalizedFilter}:${limit ?? ""}:${schema ?? ""}`;
|
||||
const trimmedFilter = filter.trim();
|
||||
const normalizedFilter = trimmedFilter.toLowerCase();
|
||||
// Remote queries (Dameng/Oracle) are case-sensitive, so the cache key must
|
||||
// preserve original casing — otherwise "TEST" and "test" collide and the
|
||||
// second lookup returns the first's stale results. Local lookups below stay
|
||||
// case-insensitive because tableMatchScore normalizes internally.
|
||||
const relaxedFilter = relaxedCompletionTableFilter(trimmedFilter);
|
||||
const cacheKey = `${connectionId}:${database}:${trimmedFilter}:${limit ?? ""}:${schema ?? ""}`;
|
||||
if (completionTablesCache.value[cacheKey]) {
|
||||
return completionTablesCache.value[cacheKey];
|
||||
}
|
||||
@@ -3932,10 +3937,10 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
if (normalizedFilter || limit) {
|
||||
let results: SqlCompletionTable[] = [];
|
||||
try {
|
||||
results = await listCompletionAssistantTables(connectionId, database, normalizedFilter, limit, schema);
|
||||
results = await listCompletionAssistantTables(connectionId, database, trimmedFilter, limit, schema);
|
||||
} catch {
|
||||
if (schema) {
|
||||
const tables = await api.listTables(connectionId, database, schema, normalizedFilter, limit);
|
||||
const tables = await api.listTables(connectionId, database, schema, trimmedFilter, limit);
|
||||
results = tables.map((table) => ({
|
||||
name: table.name,
|
||||
schema,
|
||||
@@ -3983,7 +3988,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return completionTablesCache.value[cacheKey];
|
||||
}
|
||||
|
||||
let tables = await api.listTables(connectionId, database, database, normalizedFilter, limit);
|
||||
let tables = await api.listTables(connectionId, database, database, trimmedFilter, limit);
|
||||
if (tables.length === 0 && relaxedFilter) {
|
||||
tables = await api.listTables(connectionId, database, database, relaxedFilter, expandedCompletionLimit(limit));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user