25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(editor): drop stale completion results on database switch
t8y21eb064d0f63a
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vueindex 8877919af7..4d9f21beeb 100644--- a/apps/desktop/src/components/editor/QueryEditor.vue+++ b/apps/desktop/src/components/editor/QueryEditor.vue@@ -2710,6 +2710,7 @@ watch(watch(() => props.connectionId,() => {+ completion.invalidateRequests();refreshCompletionCache();setSemanticDiagnostics([]);scheduleSemanticDiagnostics();@@ -2719,6 +2720,7 @@ watch(watch(() => props.database,() => {+ completion.invalidateRequests();refreshCompletionCache();setSemanticDiagnostics([]);scheduleSemanticDiagnostics();@@ -2728,6 +2730,7 @@ watch(watch(() => props.catalog,() => {+ completion.invalidateRequests();refreshCompletionCache();setSemanticDiagnostics([]);scheduleSemanticDiagnostics();@@ -2737,6 +2740,7 @@ watch(watch(() => props.schema,() => {+ completion.invalidateRequests();refreshCompletionCache();setSemanticDiagnostics([]);scheduleSemanticDiagnostics();diff --git a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.tsindex 9f6ae38d5a..5a82f10889 100644--- a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts@@ -101,7 +101,7 @@ function createHarness(overrides: Partial<QueryEditorProps> = {}, configureMetadparent.remove();});const provide = (explicit = true) => completion.provideSqlCompletions(new CompletionContext(currentView.state, currentView.state.selection.main.head, explicit));- return { props, currentView, view, store, settings, runtime, completion, provide, startCompletion };+ return { props, currentView, view, store, settings, runtime, metadata, completion, provide, startCompletion };}describe.each([false, true])("OceanBase standalone routine completion (semantic=%s)", (semanticCompletionEnabled) => {@@ -308,6 +308,29 @@ describe.each([false, true])("Snowflake namespace completion (semantic=%s)", (seexpect((await provide())?.options.map((option) => option.label)).toEqual(["QUOTED_TABLE"]);});+ it("drops an in-flight table response after the completion cache resets", async () => {+ const { metadata, store, props } = createHarness({ database: "a", modelValue: "SELECT * FROM " });+ let resolveOld!: (tables: SqlCompletionTable[]) => void;+ store.listCompletionTables.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ resolveOld = resolve;+ }),+ );+ const old = metadata.listCompletionTablesWithLatencyBudget("connection", "a", "", 100);+ await Promise.resolve();++ props.database = "b";+ metadata.refreshCompletionCache();+ store.listCompletionTables.mockResolvedValue([{ name: "NEW_TABLE", database: "b" }]);+ resolveOld([{ name: "OLD_TABLE", database: "a" }]);+ await old;++ expect(metadata.cachedTables.map((table) => table.name)).not.toContain("OLD_TABLE");+ const tables = await metadata.listCompletionTablesWithLatencyBudget("connection", "b", "", 100);+ expect(tables.map((table) => table.name)).toContain("NEW_TABLE");+ });+it.each([false, true])("preserves the quote-identifiers preference (%s) for mixed-case table insertion", async (quoteIdentifiers) => {const { catalogs, provide, currentView, settings } = snowflakeHarness("SELECT * FROM ");catalogs.DEFAULT_DB!.PUBLIC = ["DimCustomer"];diff --git a/apps/desktop/src/components/editor/useQueryEditorCompletionMetadata.ts b/apps/desktop/src/components/editor/useQueryEditorCompletionMetadata.tsindex aa7f336e44..794e5e0250 100644--- a/apps/desktop/src/components/editor/useQueryEditorCompletionMetadata.ts+++ b/apps/desktop/src/components/editor/useQueryEditorCompletionMetadata.ts@@ -50,6 +50,7 @@ export function useQueryEditorCompletionMetadata(options: QueryEditorCompletionM// Completion cachelet cachedTables: SqlCompletionTable[] = [];+ let completionCacheGeneration = 0;const cachedCompletionObjectsByScope = new Map<string, SqlCompletionObject[]>();@@ -548,8 +549,12 @@ export function useQueryEditorCompletionMetadata(options: QueryEditorCompletionM}function listCompletionTablesWithLatencyBudget(connectionId: string, database: string, filter: string, limit: number, schema?: string, globalSearch = false, catalog = props.catalog, currentSchema = props.schema): Promise<SqlCompletionTable[]> {+ const generation = completionCacheGeneration;const local = connectionStore.lookupLocalCompletionTables(connectionId, database, filter, limit, globalSearch ? undefined : schema, catalog).map((table) => ({ ...table, catalog: table.catalog ?? catalog, database: table.database ?? database }));const remote = connectionStore.listCompletionTables(connectionId, database, filter, limit, schema, globalSearch, currentSchema, catalog).then((tables) => {+ // A database/schema switch clears the cache while this request is still in+ // flight; never merge the old result into the new scope.+ if (generation !== completionCacheGeneration) return [];const scopedTables = tables.map((table) => ({ ...table, catalog: table.catalog ?? catalog, database: table.database ?? database }));cachedTables = mergeCompletionTables(cachedTables, scopedTables);return scopedTables;@@ -609,6 +614,7 @@ export function useQueryEditorCompletionMetadata(options: QueryEditorCompletionM}function refreshCompletionCache() {+ completionCacheGeneration++;cancelEditorSqlCompletionAnalysis();cachedTables = [];cachedCompletionObjectsByScope.clear();