refactor(connection): unify tree metadata loading
This commit is contained in:
1 file changed
+28
-72
@@ -1238,6 +1238,22 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
recordConnectionError(connectionId, error);
|
recordConnectionError(connectionId, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runConnectionTreeMetadataLoad<T>(connectionId: string, node: TreeNode | null | undefined, work: (load: TreeNodeLoadHandle) => Promise<T>): Promise<T | undefined> {
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
let load = beginTreeNodeLoad(node);
|
||||||
|
try {
|
||||||
|
await ensureConnected(connectionId);
|
||||||
|
load = reclaimTreeNodeLoad(load, node);
|
||||||
|
return await work(load);
|
||||||
|
} catch (error) {
|
||||||
|
recordMetadataLoadError(connectionId, error, load);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
finishTreeNodeLoad(load);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function withConnectionAttemptTimeout<T>(promise: Promise<T>, config: ConnectionConfig): Promise<T> {
|
async function withConnectionAttemptTimeout<T>(promise: Promise<T>, config: ConnectionConfig): Promise<T> {
|
||||||
const timeoutMs = connectionAttemptTimeoutMs(config, tunnelProfileStore.profileById);
|
const timeoutMs = connectionAttemptTimeoutMs(config, tunnelProfileStore.profileById);
|
||||||
const timeoutMessage = connectionAttemptTimeoutMessage(timeoutMs);
|
const timeoutMessage = connectionAttemptTimeoutMessage(timeoutMs);
|
||||||
@@ -4557,12 +4573,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
|
|
||||||
async function loadRedisDatabases(connectionId: string) {
|
async function loadRedisDatabases(connectionId: string) {
|
||||||
const node = findConnectionNode(connectionId);
|
const node = findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const dbs = await withMetadataLoadTimeout(connectionId, api.redisListDatabases(connectionId), "Redis databases");
|
const dbs = await withMetadataLoadTimeout(connectionId, api.redisListDatabases(connectionId), "Redis databases");
|
||||||
const config = getConfig(connectionId);
|
const config = getConfig(connectionId);
|
||||||
const visibleNames = filterVisibleDatabaseNames(
|
const visibleNames = filterVisibleDatabaseNames(
|
||||||
@@ -4597,22 +4608,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadEtcdRoot(connectionId: string) {
|
async function loadEtcdRoot(connectionId: string) {
|
||||||
const node = findConnectionNode(connectionId);
|
const node = findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const targetNode = treeNodeLoadTarget(load);
|
const targetNode = treeNodeLoadTarget(load);
|
||||||
if (!targetNode) return;
|
if (!targetNode) return;
|
||||||
const etcdAccess = await ensureEtcdAccessCapabilities(connectionId, { force: true, verifyHealth: false });
|
const etcdAccess = await ensureEtcdAccessCapabilities(connectionId, { force: true, verifyHealth: false });
|
||||||
@@ -4651,22 +4652,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
}
|
}
|
||||||
setChildren(targetNode, withSavedSqlRoot(connectionId, children, targetNode));
|
setChildren(targetNode, withSavedSqlRoot(connectionId, children, targetNode));
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadZooKeeperRoot(connectionId: string) {
|
async function loadZooKeeperRoot(connectionId: string) {
|
||||||
const node = findConnectionNode(connectionId);
|
const node = findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const targetNode = treeNodeLoadTarget(load);
|
const targetNode = treeNodeLoadTarget(load);
|
||||||
if (!targetNode) return;
|
if (!targetNode) return;
|
||||||
setChildren(
|
setChildren(
|
||||||
@@ -4688,22 +4679,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadConsulRoot(connectionId: string) {
|
async function loadConsulRoot(connectionId: string) {
|
||||||
const node = findConnectionNode(connectionId);
|
const node = findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const targetNode = treeNodeLoadTarget(load);
|
const targetNode = treeNodeLoadTarget(load);
|
||||||
if (!targetNode) return;
|
if (!targetNode) return;
|
||||||
setChildren(
|
setChildren(
|
||||||
@@ -4734,12 +4715,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadMqttTopics(connectionId: string) {
|
async function loadMqttTopics(connectionId: string) {
|
||||||
@@ -5083,12 +5059,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
|
|
||||||
async function loadMilvusDatabases(connectionId: string) {
|
async function loadMilvusDatabases(connectionId: string) {
|
||||||
const node = findConnectionNode(connectionId);
|
const node = findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const dbs = await withMetadataLoadTimeout(connectionId, api.documentListDatabases(connectionId), "Milvus databases");
|
const dbs = await withMetadataLoadTimeout(connectionId, api.documentListDatabases(connectionId), "Milvus databases");
|
||||||
const targetNode = treeNodeLoadTarget(load);
|
const targetNode = treeNodeLoadTarget(load);
|
||||||
if (!targetNode) return;
|
if (!targetNode) return;
|
||||||
@@ -5109,12 +5080,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadVectorCollections(connectionId: string, database?: string) {
|
async function loadVectorCollections(connectionId: string, database?: string) {
|
||||||
@@ -5123,12 +5089,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
const effectiveDb = database || config?.database || (config?.db_type === "chromadb" ? "default_database" : "default");
|
const effectiveDb = database || config?.database || (config?.db_type === "chromadb" ? "default_database" : "default");
|
||||||
// Milvus groups collections under a per-database node; other vector stores stay flat under the connection.
|
// Milvus groups collections under a per-database node; other vector stores stay flat under the connection.
|
||||||
const node = isMilvus && database ? findNode(treeNodes.value, `${connectionId}:${database}`) : findConnectionNode(connectionId);
|
const node = isMilvus && database ? findNode(treeNodes.value, `${connectionId}:${database}`) : findConnectionNode(connectionId);
|
||||||
if (!node) return;
|
return runConnectionTreeMetadataLoad(connectionId, node, async (load) => {
|
||||||
|
|
||||||
let load = beginTreeNodeLoad(node);
|
|
||||||
try {
|
|
||||||
await ensureConnected(connectionId);
|
|
||||||
load = reclaimTreeNodeLoad(load, node);
|
|
||||||
const collections = await withMetadataLoadTimeout(connectionId, api.vectorListCollections(connectionId, effectiveDb), "vector collections");
|
const collections = await withMetadataLoadTimeout(connectionId, api.vectorListCollections(connectionId, effectiveDb), "vector collections");
|
||||||
const sorted = [...collections].sort((a, b) => a.name.localeCompare(b.name));
|
const sorted = [...collections].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
const collectionChildren = sorted.map((info) => ({
|
const collectionChildren = sorted.map((info) => ({
|
||||||
@@ -5145,12 +5106,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
if (!targetNode) return;
|
if (!targetNode) return;
|
||||||
setChildren(targetNode, isMilvus && database ? collectionChildren : withSavedSqlRoot(connectionId, collectionChildren, targetNode));
|
setChildren(targetNode, isMilvus && database ? collectionChildren : withSavedSqlRoot(connectionId, collectionChildren, targetNode));
|
||||||
targetNode.isExpanded = true;
|
targetNode.isExpanded = true;
|
||||||
} catch (e) {
|
});
|
||||||
recordMetadataLoadError(connectionId, e, load);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
finishTreeNodeLoad(load);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadMongoCollections(connectionId: string, database: string) {
|
async function loadMongoCollections(connectionId: string, database: string) {
|
||||||
|
|||||||
Reference in new issue
Block a user