7 files changed
+97
-17
No files matched your search
@@ -37,7 +37,7 @@ import { formatSidebarTableCopyText } from "@/lib/sidebar/sidebarTableNameCopy";
|
||||
import { pruneTreeSelectionToVisibleNodeIds } from "@/lib/sidebar/sidebarTreeSelection";
|
||||
import { isEditableSidebarTypeSearchTarget, sidebarTypeSearchNextQuery } from "@/lib/sidebar/sidebarTypeSearch";
|
||||
import { isInternalDorisCatalog, usesTreeSchemaMode } from "@/lib/database/databaseFeatureSupport";
|
||||
import { connectionObjectTreeNodeSchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";
|
||||
import { connectionObjectTreeNodeSchema, connectionShouldDiscoverJdbcSchemas, connectionUsesConnectionRootSchemaMode, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";
|
||||
import {
|
||||
activeTabSidebarTarget,
|
||||
findSidebarConnectionNode,
|
||||
@@ -1582,8 +1582,10 @@ async function locateTabInSidebar(tab: QueryTab | undefined | null, align: Sideb
|
||||
|
||||
const config = connId ? store.getConfig(connId) : undefined;
|
||||
const cursorCandidate = locatesSavedSql ? null : queryCursorTableCandidate(tab, effectiveDatabaseTypeForConnection(config));
|
||||
const tabTableCandidate = locatesSavedSql || cursorCandidate ? null : tableLocateCandidateFromTarget(tabTarget, config);
|
||||
const locateTableCandidate = cursorCandidate ?? tabTableCandidate;
|
||||
const fallbackTarget = locatesSavedSql ? tabTarget : (queryContextTargetFromCandidate(tab, cursorCandidate) ?? tabTarget);
|
||||
const initialTarget = cursorCandidate ? tableTargetFromCandidate(cursorCandidate) : fallbackTarget;
|
||||
const initialTarget = locateTableCandidate ? tableTargetFromCandidate(locateTableCandidate) : fallbackTarget;
|
||||
if (!initialTarget) return;
|
||||
|
||||
// Ensure the tree is loaded deep enough to contain the preferred target.
|
||||
@@ -1608,7 +1610,7 @@ async function locateTabInSidebar(tab: QueryTab | undefined | null, align: Sideb
|
||||
clearSearchScopeFilter();
|
||||
}
|
||||
|
||||
let target = resolveLoadedLocateTarget(initialTarget, cursorCandidate);
|
||||
let target = resolveLoadedLocateTarget(initialTarget, locateTableCandidate);
|
||||
let nodePath = target ? findNodePathForTarget(target, store.treeNodes) : null;
|
||||
if (!nodePath && !locatesSavedSql) {
|
||||
// The first load may have served a stale schema cache whose async refresh
|
||||
@@ -1616,13 +1618,13 @@ async function locateTabInSidebar(tab: QueryTab | undefined | null, align: Sideb
|
||||
// table isn't in the tree yet. Force a synchronous reload and retry once so
|
||||
// locate reaches the table, not just the database (issue #715).
|
||||
await ensureTreeLoadedForTarget(treeLoadTarget, { force: true });
|
||||
target = resolveLoadedLocateTarget(initialTarget, cursorCandidate);
|
||||
target = resolveLoadedLocateTarget(initialTarget, locateTableCandidate);
|
||||
nodePath = target ? findNodePathForTarget(target, store.treeNodes) : null;
|
||||
}
|
||||
|
||||
if (!nodePath && cursorCandidate) {
|
||||
await store.loadTableForLocate(cursorCandidate);
|
||||
target = resolveLoadedLocateTarget(initialTarget, cursorCandidate);
|
||||
if (!nodePath && locateTableCandidate) {
|
||||
await store.loadTableForLocate(locateTableCandidate);
|
||||
target = resolveLoadedLocateTarget(initialTarget, locateTableCandidate);
|
||||
nodePath = target ? findNodePathForTarget(target, store.treeNodes) : null;
|
||||
}
|
||||
|
||||
@@ -1678,6 +1680,17 @@ function tableTargetFromCandidate(candidate: QueryCursorTableCandidate): ActiveT
|
||||
};
|
||||
}
|
||||
|
||||
function tableLocateCandidateFromTarget(target: ActiveTabSidebarTarget | null, config: ReturnType<typeof store.getConfig>): QueryCursorTableCandidate | null {
|
||||
if (target?.type !== "table") return null;
|
||||
const database = connectionUsesConnectionRootSchemaMode(config) && target.schema ? target.schema : target.database;
|
||||
return {
|
||||
connectionId: target.connectionId,
|
||||
database,
|
||||
schema: target.schema,
|
||||
tableName: target.tableName,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveLoadedLocateTarget(target: ActiveTabSidebarTarget, candidate: QueryCursorTableCandidate | null): ActiveTabSidebarTarget | null {
|
||||
if (!candidate) return target;
|
||||
return findLoadedTableTargetForCandidate(store.treeNodes, candidate);
|
||||
@@ -1741,12 +1754,24 @@ async function ensureTreeLoadedForTarget(target: ActiveTabSidebarTarget, opts?:
|
||||
}
|
||||
|
||||
// Find the database node
|
||||
const targetSchema = "schema" in target ? target.schema : undefined;
|
||||
const effectiveDbType = effectiveDatabaseTypeForConnection(config);
|
||||
if (target.type === "table" && connectionUsesConnectionRootSchemaMode(config)) {
|
||||
const schemaName = targetSchema || target.database;
|
||||
if (!schemaName) return;
|
||||
const schemaNode = findSchemaNode(store.treeNodes, connId, schemaName, schemaName);
|
||||
if (!schemaNode) return;
|
||||
if (force || !schemaNode.children || schemaNode.children.length === 0) {
|
||||
await store.loadTables(connId, schemaNode.database || schemaName, schemaNode.schema ?? schemaName, loadOptions);
|
||||
}
|
||||
await ensureTableObjectGroupsLoaded({ ...target, database: schemaNode.database || schemaName, schema: schemaNode.schema ?? schemaName }, loadOptions);
|
||||
return;
|
||||
}
|
||||
|
||||
const dbNode = findDatabaseNode(store.treeNodes, connId, target.database, targetCatalog, usesExactCatalogScope);
|
||||
if (!dbNode) return;
|
||||
const targetSchema = "schema" in target ? target.schema : undefined;
|
||||
const databaseChildrenLoaded = !!dbNode.children && dbNode.children.length > 0;
|
||||
const effectiveDbType = effectiveDatabaseTypeForConnection(config);
|
||||
const usesSchemaTree = usesTreeSchemaMode(effectiveDbType) && !connectionUsesDatabaseObjectTreeMode(config);
|
||||
const usesSchemaTree = (usesTreeSchemaMode(effectiveDbType) && !connectionUsesDatabaseObjectTreeMode(config)) || connectionShouldDiscoverJdbcSchemas(config);
|
||||
const shouldLoadSchemaTables = target.type === "table" && !!targetSchema && usesSchemaTree;
|
||||
if (!force && databaseChildrenLoaded && !shouldLoadSchemaTables) return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user