fix(quick-open): search unloaded tables after cold start
This commit is contained in:
6 files changed
+211
-29
No files matched your search
@@ -112,6 +112,35 @@ describe("connectionStore completion assistant", () => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it("does not replace the active connection during a cold metadata search", async () => {
|
||||
const connectDb = vi.fn().mockResolvedValue("pg-1");
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "users", kind: "table", schema: "public" }],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
connectDb,
|
||||
connectionDatabaseInfo: vi.fn().mockResolvedValue(null),
|
||||
connectionIdentifierQuote: vi.fn().mockResolvedValue('"'),
|
||||
completionAssistantSearch,
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [postgresConnection()];
|
||||
store.activeConnectionId = "already-active";
|
||||
|
||||
const tables = await store.listCompletionTables("pg-1", "app", "users", 20, undefined, true, undefined, undefined, { activateConnection: false });
|
||||
|
||||
expect(connectDb).toHaveBeenCalledOnce();
|
||||
expect(store.connectedIds.has("pg-1")).toBe(true);
|
||||
expect(store.activeConnectionId).toBe("already-active");
|
||||
expect(tables).toEqual([{ name: "users", schema: "public", type: "table" }]);
|
||||
});
|
||||
|
||||
it("deduplicates in-flight assistant table requests", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "accounts", kind: "table", schema: "public" }],
|
||||
|
||||
@@ -2813,7 +2813,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
invalidateObjectBrowserRowsCache({ connectionId, database });
|
||||
}
|
||||
|
||||
async function ensureConnected(connectionId: string) {
|
||||
async function ensureConnected(connectionId: string, options: { activate?: boolean } = {}) {
|
||||
if (connectedIds.value.has(connectionId)) {
|
||||
if (hasRecentConnectionHealthCheck(connectionId)) return;
|
||||
// Optimistic: verify backend pool is actually healthy
|
||||
@@ -2842,6 +2842,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const existingConnect = connectInFlight.get(connectionId);
|
||||
if (existingConnect) {
|
||||
await existingConnect;
|
||||
if (options.activate !== false) activeConnectionId.value = connectionId;
|
||||
return;
|
||||
}
|
||||
const localAttempt = beginLocalConnectionAttempt(connectionId);
|
||||
@@ -2860,12 +2861,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await refreshConnectionIdentifierQuote(connectionId, config);
|
||||
markSuccessfulLocalConnectionAttempt(connectionId, localAttempt);
|
||||
markConnectionHealthChecked(connectionId);
|
||||
activeConnectionId.value = connectionId;
|
||||
clearConnectionError(connectionId);
|
||||
})();
|
||||
connectInFlight.set(connectionId, connectPromise);
|
||||
try {
|
||||
await connectPromise;
|
||||
if (options.activate !== false) activeConnectionId.value = connectionId;
|
||||
} catch (e) {
|
||||
if (isCancelledLocalConnectionAttempt(connectionId, localAttempt)) {
|
||||
clearConnectionError(connectionId);
|
||||
@@ -5924,7 +5925,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return api.listTables(connectionId, database, schema, filter, limit);
|
||||
}
|
||||
|
||||
async function listCompletionTables(connectionId: string, database: string, filter = "", limit?: number, schema?: string, globalSearch = false, currentSchema?: string, catalog?: string): Promise<SqlCompletionTable[]> {
|
||||
async function listCompletionTables(connectionId: string, database: string, filter = "", limit?: number, schema?: string, globalSearch = false, currentSchema?: string, catalog?: string, options: { activateConnection?: boolean } = {}): Promise<SqlCompletionTable[]> {
|
||||
const trimmedFilter = filter.trim();
|
||||
const normalizedFilter = trimmedFilter.toLowerCase();
|
||||
// Remote queries (Dameng/Oracle) are case-sensitive, so the cache key must
|
||||
@@ -5940,7 +5941,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return withCompletionInFlight(
|
||||
`${cacheKey}:tables`,
|
||||
async () => {
|
||||
await ensureConnected(connectionId);
|
||||
await ensureConnected(connectionId, { activate: options.activateConnection !== false });
|
||||
|
||||
if (isSchemaAwareDatabase(connectionId)) {
|
||||
if (normalizedFilter || limit) {
|
||||
|
||||
Reference in new issue
Block a user