fix(schema): prevent repeated schema option loads
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user