Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(schema): prevent repeated schema option loads

t8y25ce2cce85bf9
diff --git a/src/composables/useSchemaOptions.ts b/src/composables/useSchemaOptions.ts
index 480b0cae81..f177a4c1bf 100644
--- a/src/composables/useSchemaOptions.ts
+++ b/src/composables/useSchemaOptions.ts
@@ -3,6 +3,10 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { isSchemaAware as isSchemaAwareType, isSingleDatabase } from "@/lib/databaseCapabilities";
import * as api from "@/lib/api";
+export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
+ return Object.prototype.hasOwnProperty.call(options, key);
+}
+
export function useSchemaOptions() {
const connectionStore = useConnectionStore();
@@ -22,12 +26,16 @@ export function useSchemaOptions() {
const dbType = connectionStore.getConfig(connectionId)?.db_type;
if (!database && !isSingleDatabase(dbType)) return;
const key = cacheKey(connectionId, database);
+ if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
if (loadingSchemaOptions.value[key]) return;
loadingSchemaOptions.value[key] = true;
try {
await connectionStore.ensureConnected(connectionId);
schemaOptions.value[key] = await api.listSchemas(connectionId, database);
+ } catch (e) {
+ schemaOptions.value[key] = [];
+ throw e;
} finally {
loadingSchemaOptions.value[key] = false;
}
diff --git a/tests/schemaOptions.test.ts b/tests/schemaOptions.test.ts
new file mode 100644
index 0000000000..2fa0685080
--- /dev/null
+++ b/tests/schemaOptions.test.ts
@@ -0,0 +1,12 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { hasSchemaOptionsCacheEntry } from "../src/composables/useSchemaOptions.ts";
+
+test("treats an empty schema option list as a loaded cache entry", () => {
+ const options = {
+ "conn:db": [],
+ };
+
+ assert.equal(hasSchemaOptionsCacheEntry(options, "conn:db"), true);
+ assert.equal(hasSchemaOptionsCacheEntry(options, "conn:other"), false);
+});