fix(sidebar): cancel stale table search work across modes

This commit is contained in:
jearhe authored and GitHub committed 2026-08-16 14:09:50 +08:00
1 parent e671b3da7d
commit 71136377e5
8 files changed
+763 -24

No files matched your search

+32 -6
View File
@@ -198,6 +198,19 @@ function sidebarObjectGroupPageSize(): number {
return typeof size === "number" && size > 0 ? size : 500;
}
/**
* Upper bound for a single remote fuzzy table-search result set.
*
* Every fuzzy match travels database → IPC → store → tree rendering, so an
* unbounded result set (e.g. a single-letter query against a large schema)
* would push thousands of rows through the whole pipeline. The budget is 4×
* the default page size (500) and comfortably covers the reported #6190
* schema (801 fuzzy matches) while keeping a single IPC payload bounded.
* Queries whose fuzzy match set exceeds the budget are truncated; narrowing
* the query reaches later tables.
*/
export const SIDEBAR_TABLE_SEARCH_RESULT_BUDGET = 2000;
function isFlatMqConnection(config: ConnectionConfig | undefined): boolean {
if (!config || config.db_type !== "mq") return false;
if (config.driver_profile === "kafka" || config.driver_profile === "rocketmq" || config.driver_profile === "rabbitmq") return true;
@@ -1855,7 +1868,14 @@ export const useConnectionStore = defineStore("connection", () => {
catalog: options.node.catalog,
});
const tableNameFilter = effectiveTableNameFilterForNode(options.node, userTableNameFilter);
const fetchLimit = searchFilter ? options.pageSize : options.pageSize + 1;
// A search must never truncate the fuzzy result set to the first page: the
// target table can sort beyond it (e.g. "T_Erp_Nc_SuPlan_List" for
// "erpncs" in a large ERP schema), which silently drops it from the first
// search even though later, narrower queries succeed. Results are bounded
// by SIDEBAR_TABLE_SEARCH_RESULT_BUDGET so a wide fuzzy query cannot push
// an unbounded result set through database → IPC → store → tree rendering.
// Unfiltered loads keep the page+1 probe used for load-more detection.
const fetchLimit = searchFilter ? SIDEBAR_TABLE_SEARCH_RESULT_BUDGET : options.pageSize + 1;
const fetchOffset = searchFilter ? undefined : options.offset;
const tables = await loadCachedMetadataListPage<TableInfo[]>(
metadataListCacheScope({
@@ -1964,7 +1984,11 @@ export const useConnectionStore = defineStore("connection", () => {
schema: options.effectiveSchema ?? options.querySchema,
nodeKind: "simple-tables",
});
const fetchLimit = searchFilter ? options.pageSize : options.pageSize + 1;
// A search must never truncate the fuzzy result set to the first page (see
// loadPagedTableGroupChildren); results are bounded by
// SIDEBAR_TABLE_SEARCH_RESULT_BUDGET, and unfiltered loads keep the
// page+1 probe.
const fetchLimit = searchFilter ? SIDEBAR_TABLE_SEARCH_RESULT_BUDGET : options.pageSize + 1;
const fetchOffset = searchFilter ? undefined : options.offset;
const tables = await loadCachedMetadataListPage<TableInfo[]>(
metadataListCacheScope({
@@ -4674,6 +4698,8 @@ export const useConnectionStore = defineStore("connection", () => {
const configForScope = getConfig(connectionId);
const simpleObjectDisplayForScope = useSettingsStore().editorSettings.sidebarObjectDisplay === "simple";
const objectTypesForScope = simpleObjectDisplayForScope ? supportedSidebarObjectTypes(configForScope) : undefined;
const searchFilterForScope = activeTreeLoadSearchFilter(options);
const pageSizeForScope = sidebarObjectGroupPageSize();
return runTreeMetadataLoad(
{
kind: "schema-tables",
@@ -4682,8 +4708,8 @@ export const useConnectionStore = defineStore("connection", () => {
schema: undefined,
nodeKind: "database",
objectTypes: objectTypesForScope,
searchFilter: activeTreeLoadSearchFilter(options),
limit: simpleObjectDisplayForScope ? sidebarObjectGroupPageSize() + 1 : undefined,
searchFilter: searchFilterForScope,
limit: simpleObjectDisplayForScope ? (searchFilterForScope ? SIDEBAR_TABLE_SEARCH_RESULT_BUDGET : pageSizeForScope + 1) : undefined,
offset: 0,
sidebarDisplayMode: simpleObjectDisplayForScope ? "simple" : "grouped",
driverProfile: metadataDriverProfile(configForScope),
@@ -4710,8 +4736,8 @@ export const useConnectionStore = defineStore("connection", () => {
return;
}
}
const pageSize = sidebarObjectGroupPageSize();
const fetchLimit = searchFilter ? pageSize : pageSize + 1;
const pageSize = pageSizeForScope;
const fetchLimit = searchFilter ? SIDEBAR_TABLE_SEARCH_RESULT_BUDGET : pageSize + 1;
const fetchOffset = searchFilter ? undefined : 0;
const tables = await withMetadataLoadTimeout(connectionId, listTablesWithOptionalTableNameFilter(connectionId, database, "", searchFilter, fetchLimit, fetchOffset, objectTypesForScope, catalog, tableNameFilter), "tables");
const hasMore = searchFilter ? false : tables.length > pageSize;