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

@@ -126,4 +126,42 @@ describe("connectionStore Doris catalog tree", () => {
["iceberg", "sales", "tree.queries"],
]);
});
it("uses the bounded fuzzy-search budget for external catalog tables", async () => {
const listTables = vi.fn().mockResolvedValue([{ name: "late_orders", table_type: "BASE TABLE", comment: null }]);
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
vi.doMock("@/lib/backend/api", () => ({
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
listTables,
loadSchemaCache: vi.fn().mockResolvedValue(null),
saveConnections: vi.fn().mockResolvedValue(undefined),
saveSchemaCache: vi.fn().mockResolvedValue(undefined),
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
}));
const { useConnectionStore } = await import("@/stores/connectionStore");
const { useSettingsStore } = await import("@/stores/settingsStore");
const store = useConnectionStore();
const settingsStore = useSettingsStore();
settingsStore.editorSettings.sidebarObjectDisplay = "simple";
settingsStore.desktopSettings.sidebar_table_page_size = 500;
const connection = starRocksConnection();
const database = databaseNode(connection.id, "hive", "sales");
store.connections = [connection];
store.connectedIds.add(connection.id);
store.treeNodes = [{ id: connection.id, label: connection.name, type: "connection", connectionId: connection.id, children: [catalogNode(connection.id, "hive", "Hive", [database])] }];
store.setSidebarTableSearchQuery(database.id, "orders");
await store.loadTreeNodeChildren(database, {
force: true,
searchFilter: "orders",
sidebarTableSearchParentId: database.id,
expectedSidebarTableSearchQuery: "orders",
});
expect(listTables.mock.calls[0]?.[4]).toBe(2000);
expect(listTables.mock.calls[0]?.[5]).toBeUndefined();
expect(listTables.mock.calls[0]?.[7]).toBe("hive");
});
});
@@ -12,6 +12,11 @@ function installLocalStorage() {
});
}
// Mirrors SIDEBAR_TABLE_SEARCH_RESULT_BUDGET in connectionStore.ts (4× the
// default sidebar_table_page_size of 500). Kept as a local constant because
// connectionStore must stay dynamically imported for vi.doMock isolation.
const SIDEBAR_SEARCH_RESULT_BUDGET = 2000;
function postgresConnection(): ConnectionConfig {
return {
id: "pg-1",
@@ -3165,7 +3170,7 @@ describe("connectionStore metadata loading", () => {
expect(tablesGroup.objectCount).toBe(5);
expect(tablesGroup.isLoading).toBe(false);
expect(listTables.mock.calls.map((call) => [call[3], call[4], call[5]])).toEqual([
["0003", 2, undefined],
["0003", SIDEBAR_SEARCH_RESULT_BUDGET, undefined],
[undefined, 3, 0],
[undefined, 3, 0],
[undefined, 3, 2],
@@ -3219,7 +3224,7 @@ describe("connectionStore metadata loading", () => {
store.sidebarSearchQuery = "orders";
await store.loadObjectGroupChildren(tablesGroup, { force: true });
expect(listTables).toHaveBeenLastCalledWith(connection.id, "basic", "basic", "orders", 200, undefined, ["TABLE"]);
expect(listTables).toHaveBeenLastCalledWith(connection.id, "basic", "basic", "orders", SIDEBAR_SEARCH_RESULT_BUDGET, undefined, ["TABLE"]);
expect(tablesGroup.children?.map((node) => node.label)).toEqual(["orders"]);
let resolveAncestorLoad!: (tables: TableInfo[]) => void;