fix(query): reload connection config before execute
This commit is contained in:
@@ -128,6 +128,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
let layoutPersistTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const staleTreeRefreshIds = new Set<string>();
|
||||
let beforeConnectHandler: BeforeConnectHandler | null = null;
|
||||
let initFromDiskPromise: Promise<void> | null = null;
|
||||
|
||||
function startEditing(id: string) {
|
||||
editingConnectionId.value = id;
|
||||
@@ -660,7 +661,11 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
|
||||
async function ensureConnected(connectionId: string) {
|
||||
if (connectedIds.value.has(connectionId)) return;
|
||||
const config = getConfig(connectionId);
|
||||
let config = getConfig(connectionId);
|
||||
if (!config) {
|
||||
await initFromDisk();
|
||||
config = getConfig(connectionId);
|
||||
}
|
||||
if (!config) {
|
||||
const error = new Error("Connection config not found");
|
||||
recordConnectionError(connectionId, error);
|
||||
@@ -1737,15 +1742,22 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
|
||||
async function initFromDisk() {
|
||||
pinnedTreeNodeIds.value = await loadPinnedTreeNodeIds();
|
||||
const saved = await api.loadConnections();
|
||||
connections.value = saved.map(normalizeConnection);
|
||||
const savedLayout = await api.loadSidebarLayout();
|
||||
sidebarLayout.value = reconcileLayout(
|
||||
connections.value.map((c) => c.id),
|
||||
savedLayout,
|
||||
);
|
||||
rebuildTreeNodes();
|
||||
if (!initFromDiskPromise) {
|
||||
initFromDiskPromise = (async () => {
|
||||
pinnedTreeNodeIds.value = await loadPinnedTreeNodeIds();
|
||||
const saved = await api.loadConnections();
|
||||
connections.value = saved.map(normalizeConnection);
|
||||
const savedLayout = await api.loadSidebarLayout();
|
||||
sidebarLayout.value = reconcileLayout(
|
||||
connections.value.map((c) => c.id),
|
||||
savedLayout,
|
||||
);
|
||||
rebuildTreeNodes();
|
||||
})().finally(() => {
|
||||
initFromDiskPromise = null;
|
||||
});
|
||||
}
|
||||
await initFromDiskPromise;
|
||||
}
|
||||
|
||||
function addEphemeralConnection(config: ConnectionConfig) {
|
||||
|
||||
@@ -558,6 +558,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
let useAgentResultSession = false;
|
||||
try {
|
||||
const connStore = useConnectionStore();
|
||||
await connStore.ensureConnected(tab.connectionId);
|
||||
const conn = connStore.getConfig(tab.connectionId);
|
||||
const useAgentCursor = !!conn?.db_type && AGENT_DRIVER_TYPES.has(conn.db_type);
|
||||
const queryTimeoutSecs =
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import test from "node:test";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { useConnectionStore } from "../../apps/desktop/src/stores/connectionStore.ts";
|
||||
import { useQueryStore } from "../../apps/desktop/src/stores/queryStore.ts";
|
||||
import type { ConnectionConfig } from "../../apps/desktop/src/types/database.ts";
|
||||
import type { QueryResult } from "../../apps/desktop/src/types/database.ts";
|
||||
|
||||
function installMemoryStorage() {
|
||||
@@ -22,6 +24,18 @@ function installMemoryStorage() {
|
||||
};
|
||||
}
|
||||
|
||||
function conn(id: string): ConnectionConfig {
|
||||
return {
|
||||
id,
|
||||
name: id,
|
||||
db_type: "postgres",
|
||||
host: "localhost",
|
||||
port: 5432,
|
||||
username: "postgres",
|
||||
password: "",
|
||||
};
|
||||
}
|
||||
|
||||
test("setErrorResult stops loading and shows the error result", () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
@@ -41,11 +55,14 @@ test("setErrorResult stops loading and shows the error result", () => {
|
||||
test("evicting cached tab results releases multi-result payloads and sessions", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let executeCount = 0;
|
||||
const closedSessions: string[] = [];
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
|
||||
globalThis.fetch = (async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/execute-multi") {
|
||||
|
||||
Reference in New Issue
Block a user