feat(sidebar): page full table search results under database
This commit is contained in:
5 files changed
+146
-43
No files matched your search
@@ -1094,8 +1094,9 @@ function openDriverStoreForInstallError(errMsg: string, node: TreeNode = activeN
|
|||||||
|
|
||||||
async function loadMoreObjectGroupChildren() {
|
async function loadMoreObjectGroupChildren() {
|
||||||
const node = activeNode.value;
|
const node = activeNode.value;
|
||||||
|
const searchFilter = node.loadMore?.parentId ? connectionStore.sidebarTableSearchQueries[node.loadMore.parentId]?.trim() || "" : "";
|
||||||
try {
|
try {
|
||||||
await connectionStore.loadMoreObjectGroupChildren(node);
|
await connectionStore.loadMoreObjectGroupChildren(node, { searchFilter });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
toast(t("connection.connectFailed", { message: translateBackendError(t, e) }), 5000);
|
toast(t("connection.connectFailed", { message: translateBackendError(t, e) }), 5000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3244,6 +3244,88 @@ describe("connectionStore metadata loading", () => {
|
|||||||
expect(listTables).toHaveBeenCalledTimes(5);
|
expect(listTables).toHaveBeenCalledTimes(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("pages table-scoped search results instead of truncating at the search budget", async () => {
|
||||||
|
const tables = Array.from({ length: 5 }, (_, index) => ({
|
||||||
|
name: `t_${String(index + 1).padStart(4, "0")}`,
|
||||||
|
table_type: "TABLE" as const,
|
||||||
|
comment: null,
|
||||||
|
}));
|
||||||
|
const listTables = vi.fn((_connectionId: string, _database: string, _schema: string, searchFilter?: string, limit?: number, offset?: number) => {
|
||||||
|
const matches = searchFilter ? tables.filter((table) => table.name.includes(searchFilter)) : tables;
|
||||||
|
const start = offset ?? 0;
|
||||||
|
return Promise.resolve(matches.slice(start, start + (limit ?? matches.length)));
|
||||||
|
});
|
||||||
|
|
||||||
|
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 = "grouped";
|
||||||
|
settingsStore.desktopSettings.sidebar_table_page_size = 2;
|
||||||
|
|
||||||
|
const connection = mysqlConnection();
|
||||||
|
const tablesGroup: TreeNode = {
|
||||||
|
id: "mysql-1:app:__tables",
|
||||||
|
label: "tree.tables",
|
||||||
|
type: "group-tables",
|
||||||
|
connectionId: connection.id,
|
||||||
|
database: "app",
|
||||||
|
isExpanded: true,
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
store.connections = [connection];
|
||||||
|
store.connectedIds.add(connection.id);
|
||||||
|
store.treeNodes = [
|
||||||
|
{
|
||||||
|
id: connection.id,
|
||||||
|
label: connection.name,
|
||||||
|
type: "connection",
|
||||||
|
connectionId: connection.id,
|
||||||
|
isExpanded: true,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: "mysql-1:app",
|
||||||
|
label: "app",
|
||||||
|
type: "database",
|
||||||
|
connectionId: connection.id,
|
||||||
|
database: "app",
|
||||||
|
isExpanded: true,
|
||||||
|
children: [tablesGroup],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
store.sidebarTableSearchQueries[tablesGroup.id] = "t";
|
||||||
|
await store.loadObjectGroupChildren(tablesGroup, {
|
||||||
|
force: true,
|
||||||
|
searchFilter: "t",
|
||||||
|
sidebarTableSearchParentId: tablesGroup.id,
|
||||||
|
expectedSidebarTableSearchQuery: "t",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(tablesGroup.children?.map((child) => child.label)).toEqual(["t_0001", "t_0002", "tree.loadMore"]);
|
||||||
|
expect(tablesGroup.children?.at(-1)?.type).toBe("load-more");
|
||||||
|
expect(listTables.mock.calls[0].slice(3, 6)).toEqual(["t", 3, 0]);
|
||||||
|
|
||||||
|
await store.loadMoreObjectGroupChildren(tablesGroup.children!.at(-1)!, { searchFilter: "t" });
|
||||||
|
|
||||||
|
expect(tablesGroup.children?.map((child) => child.label)).toEqual(["t_0001", "t_0002", "t_0003", "t_0004", "tree.loadMore"]);
|
||||||
|
expect(tablesGroup.children?.at(-1)?.type).toBe("load-more");
|
||||||
|
expect(listTables.mock.calls[1].slice(3, 6)).toEqual(["t", 3, 2]);
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps connection-name matches out of object metadata filters", async () => {
|
it("keeps connection-name matches out of object metadata filters", async () => {
|
||||||
const listTables = vi.fn((_connectionId: string, _database: string, _schema: string, searchFilter?: string) => Promise.resolve(searchFilter === "orders" || !searchFilter ? [{ name: "orders", table_type: "TABLE" as const, comment: null }] : []));
|
const listTables = vi.fn((_connectionId: string, _database: string, _schema: string, searchFilter?: string) => Promise.resolve(searchFilter === "orders" || !searchFilter ? [{ name: "orders", table_type: "TABLE" as const, comment: null }] : []));
|
||||||
|
|
||||||
|
|||||||
@@ -2087,6 +2087,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
offset: number;
|
offset: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
searchFilter?: string;
|
searchFilter?: string;
|
||||||
|
pagedSearch?: boolean;
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
}): Promise<{ children: TreeNode[]; objectCount: number; hasMore: boolean; nextOffset: number; loadMoreParent?: TableTreeLoadMoreParent }> {
|
}): Promise<{ children: TreeNode[]; objectCount: number; hasMore: boolean; nextOffset: number; loadMoreParent?: TableTreeLoadMoreParent }> {
|
||||||
if (!options.node.connectionId || options.node.database == null) {
|
if (!options.node.connectionId || options.node.database == null) {
|
||||||
@@ -2102,15 +2103,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
});
|
});
|
||||||
const tableNameFilter = effectiveTableNameFilterForNode(options.node, userTableNameFilter);
|
const tableNameFilter = effectiveTableNameFilterForNode(options.node, userTableNameFilter);
|
||||||
const sourceRevision = tableListSourceRevision(options.node.connectionId);
|
const sourceRevision = tableListSourceRevision(options.node.connectionId);
|
||||||
// A search must never truncate the fuzzy result set to the first page: the
|
// Table-scoped search must page through the full ordered result set, just
|
||||||
// target table can sort beyond it (e.g. "T_Erp_Nc_SuPlan_List" for
|
// like unfiltered loads, instead of silently stopping at the first budget
|
||||||
// "erpncs" in a large ERP schema), which silently drops it from the first
|
// window. Global sidebar search keeps the bounded single-shot fetch.
|
||||||
// search even though later, narrower queries succeed. Results are bounded
|
const paginate = options.pagedSearch || !searchFilter;
|
||||||
// by SIDEBAR_TABLE_SEARCH_RESULT_BUDGET so a wide fuzzy query cannot push
|
const fetchLimit = paginate ? options.pageSize + 1 : SIDEBAR_TABLE_SEARCH_RESULT_BUDGET;
|
||||||
// an unbounded result set through database → IPC → store → tree rendering.
|
const fetchOffset = paginate ? options.offset : undefined;
|
||||||
// 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[]>(
|
const tables = await loadCachedMetadataListPage<TableInfo[]>(
|
||||||
metadataListCacheScope({
|
metadataListCacheScope({
|
||||||
kind: "table-list-page",
|
kind: "table-list-page",
|
||||||
@@ -2128,7 +2126,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
() => listTablesWithOptionalTableNameFilter(options.node.connectionId!, options.node.database!, options.querySchema, searchFilter, fetchLimit, fetchOffset, options.objectTypes, options.node.catalog, tableNameFilter),
|
() => listTablesWithOptionalTableNameFilter(options.node.connectionId!, options.node.database!, options.querySchema, searchFilter, fetchLimit, fetchOffset, options.objectTypes, options.node.catalog, tableNameFilter),
|
||||||
{ force: options.force },
|
{ force: options.force },
|
||||||
);
|
);
|
||||||
const hasMore = searchFilter ? false : tables.length > options.pageSize;
|
const hasMore = paginate ? tables.length > options.pageSize : false;
|
||||||
const pageTables = hasMore ? tables.slice(0, options.pageSize) : tables;
|
const pageTables = hasMore ? tables.slice(0, options.pageSize) : tables;
|
||||||
if (tableListSourceRevision(options.node.connectionId) === sourceRevision) {
|
if (tableListSourceRevision(options.node.connectionId) === sourceRevision) {
|
||||||
indexCompletionTables(options.node.connectionId, options.node.database, options.effectiveSchema, tableInfosToCompletionTables(pageTables, options.effectiveSchema));
|
indexCompletionTables(options.node.connectionId, options.node.database, options.effectiveSchema, tableInfosToCompletionTables(pageTables, options.effectiveSchema));
|
||||||
@@ -2223,6 +2221,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
offset: number;
|
offset: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
searchFilter?: string;
|
searchFilter?: string;
|
||||||
|
pagedSearch?: boolean;
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
}): Promise<{ children: TreeNode[]; objectCount: number; hasMore: boolean; nextOffset: number; loadMoreParent?: TableTreeLoadMoreParent }> {
|
}): Promise<{ children: TreeNode[]; objectCount: number; hasMore: boolean; nextOffset: number; loadMoreParent?: TableTreeLoadMoreParent }> {
|
||||||
const searchFilter = (options.searchFilter ?? sidebarSearchQuery.value) || undefined;
|
const searchFilter = (options.searchFilter ?? sidebarSearchQuery.value) || undefined;
|
||||||
@@ -2233,12 +2232,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
nodeKind: "simple-tables",
|
nodeKind: "simple-tables",
|
||||||
});
|
});
|
||||||
const sourceRevision = tableListSourceRevision(options.connectionId);
|
const sourceRevision = tableListSourceRevision(options.connectionId);
|
||||||
// A search must never truncate the fuzzy result set to the first page (see
|
const paginate = options.pagedSearch || !searchFilter;
|
||||||
// loadPagedTableGroupChildren); results are bounded by
|
const fetchLimit = paginate ? options.pageSize + 1 : SIDEBAR_TABLE_SEARCH_RESULT_BUDGET;
|
||||||
// SIDEBAR_TABLE_SEARCH_RESULT_BUDGET, and unfiltered loads keep the
|
const fetchOffset = paginate ? options.offset : undefined;
|
||||||
// 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[]>(
|
const tables = await loadCachedMetadataListPage<TableInfo[]>(
|
||||||
metadataListCacheScope({
|
metadataListCacheScope({
|
||||||
kind: "table-list-page",
|
kind: "table-list-page",
|
||||||
@@ -2255,7 +2251,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
() => listTablesWithOptionalTableNameFilter(options.connectionId, options.database, options.querySchema, searchFilter, fetchLimit, fetchOffset, undefined, undefined, tableNameFilter),
|
() => listTablesWithOptionalTableNameFilter(options.connectionId, options.database, options.querySchema, searchFilter, fetchLimit, fetchOffset, undefined, undefined, tableNameFilter),
|
||||||
{ force: options.force },
|
{ force: options.force },
|
||||||
);
|
);
|
||||||
const hasMore = searchFilter ? false : tables.length > options.pageSize;
|
const hasMore = paginate ? tables.length > options.pageSize : false;
|
||||||
const pageTables = hasMore ? tables.slice(0, options.pageSize) : tables;
|
const pageTables = hasMore ? tables.slice(0, options.pageSize) : tables;
|
||||||
if (tableListSourceRevision(options.connectionId) === sourceRevision) {
|
if (tableListSourceRevision(options.connectionId) === sourceRevision) {
|
||||||
indexCompletionTables(options.connectionId, options.database, options.effectiveSchema, tableInfosToCompletionTables(pageTables, options.effectiveSchema));
|
indexCompletionTables(options.connectionId, options.database, options.effectiveSchema, tableInfosToCompletionTables(pageTables, options.effectiveSchema));
|
||||||
@@ -5553,9 +5549,10 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
pageSize,
|
pageSize,
|
||||||
searchFilter: options?.searchFilter === "" ? "" : searchFilter || undefined,
|
searchFilter: options?.searchFilter === "" ? "" : searchFilter || undefined,
|
||||||
|
pagedSearch: isSidebarTableSearch,
|
||||||
force: options?.force,
|
force: options?.force,
|
||||||
});
|
});
|
||||||
children = page.hasMore && !searchFilter ? appendTableTreeLoadMoreNode(page.children, buildLoadMoreNode(node, page.nextOffset, pageSize), page.loadMoreParent) : page.children;
|
children = page.hasMore && (!searchFilter || isSidebarTableSearch) ? appendTableTreeLoadMoreNode(page.children, buildLoadMoreNode(node, page.nextOffset, pageSize), page.loadMoreParent) : page.children;
|
||||||
nextObjectCount = page.objectCount;
|
nextObjectCount = page.objectCount;
|
||||||
} else if (simpleObjectDisplay) {
|
} else if (simpleObjectDisplay) {
|
||||||
// The synthetic public scope contains no tables. Avoid issuing a
|
// The synthetic public scope contains no tables. Avoid issuing a
|
||||||
@@ -5706,9 +5703,10 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
pageSize: sidebarObjectGroupPageSize(),
|
pageSize: sidebarObjectGroupPageSize(),
|
||||||
searchFilter: options?.searchFilter === "" ? "" : searchFilter || undefined,
|
searchFilter: options?.searchFilter === "" ? "" : searchFilter || undefined,
|
||||||
|
pagedSearch: isSidebarTableSearch,
|
||||||
force: options?.force,
|
force: options?.force,
|
||||||
});
|
});
|
||||||
children = page.hasMore && !searchFilter ? appendTableTreeLoadMoreNode(page.children, buildLoadMoreNode(node, page.nextOffset, sidebarObjectGroupPageSize()), page.loadMoreParent) : page.children;
|
children = page.hasMore && (!searchFilter || isSidebarTableSearch) ? appendTableTreeLoadMoreNode(page.children, buildLoadMoreNode(node, page.nextOffset, sidebarObjectGroupPageSize()), page.loadMoreParent) : page.children;
|
||||||
nextObjectCount = page.objectCount;
|
nextObjectCount = page.objectCount;
|
||||||
} else {
|
} else {
|
||||||
const pageSize = sidebarObjectGroupPageSize();
|
const pageSize = sidebarObjectGroupPageSize();
|
||||||
@@ -5791,6 +5789,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
schema: parent.schema,
|
schema: parent.schema,
|
||||||
nodeKind: parent.type,
|
nodeKind: parent.type,
|
||||||
objectTypes: objectTypesForScope,
|
objectTypes: objectTypesForScope,
|
||||||
|
searchFilter: options?.searchFilter,
|
||||||
limit: loadMore.pageSize + 1,
|
limit: loadMore.pageSize + 1,
|
||||||
offset: loadMore.offset,
|
offset: loadMore.offset,
|
||||||
sidebarDisplayMode: useSettingsStore().editorSettings.sidebarObjectDisplay,
|
sidebarDisplayMode: useSettingsStore().editorSettings.sidebarObjectDisplay,
|
||||||
@@ -5819,6 +5818,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
nonTableObjectTypes: [],
|
nonTableObjectTypes: [],
|
||||||
offset: loadMore.offset,
|
offset: loadMore.offset,
|
||||||
pageSize: loadMore.pageSize,
|
pageSize: loadMore.pageSize,
|
||||||
|
searchFilter: options?.searchFilter,
|
||||||
|
pagedSearch: !!options?.searchFilter,
|
||||||
force: false,
|
force: false,
|
||||||
});
|
});
|
||||||
const targetParent = treeNodeLoadRelatedTarget(load, parent);
|
const targetParent = treeNodeLoadRelatedTarget(load, parent);
|
||||||
@@ -5828,7 +5829,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
const nextChildren = page.hasMore ? appendTableTreeLoadMoreNode(mergedChildren, buildLoadMoreNode(targetParent, page.nextOffset, loadMore.pageSize), page.loadMoreParent) : mergedChildren;
|
const nextChildren = page.hasMore ? appendTableTreeLoadMoreNode(mergedChildren, buildLoadMoreNode(targetParent, page.nextOffset, loadMore.pageSize), page.loadMoreParent) : mergedChildren;
|
||||||
targetParent.objectCount = mergedChildren.length;
|
targetParent.objectCount = mergedChildren.length;
|
||||||
setChildren(targetParent, nextChildren);
|
setChildren(targetParent, nextChildren);
|
||||||
await savePersistedTreeChildren(schemaCacheKey(parentConnectionId, parentDatabase, parent.schema || "", ownerAwareMetadataCacheVersion(config, "objects-simple-v8")), nextChildren);
|
if (!options?.searchFilter) {
|
||||||
|
await savePersistedTreeChildren(schemaCacheKey(parentConnectionId, parentDatabase, parent.schema || "", ownerAwareMetadataCacheVersion(config, "objects-simple-v8")), nextChildren);
|
||||||
|
}
|
||||||
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
||||||
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
||||||
return;
|
return;
|
||||||
@@ -5855,6 +5858,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
offset: loadMore.offset,
|
offset: loadMore.offset,
|
||||||
pageSize: loadMore.pageSize,
|
pageSize: loadMore.pageSize,
|
||||||
searchFilter: options?.searchFilter,
|
searchFilter: options?.searchFilter,
|
||||||
|
pagedSearch: !!options?.searchFilter,
|
||||||
force: false,
|
force: false,
|
||||||
});
|
});
|
||||||
const targetParent = treeNodeLoadRelatedTarget(load, parent);
|
const targetParent = treeNodeLoadRelatedTarget(load, parent);
|
||||||
@@ -5881,7 +5885,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
nextChildren = page.hasMore ? [...mergedChildren, buildLoadMoreNode(targetParent, page.nextOffset, loadMore.pageSize)] : mergedChildren;
|
nextChildren = page.hasMore ? [...mergedChildren, buildLoadMoreNode(targetParent, page.nextOffset, loadMore.pageSize)] : mergedChildren;
|
||||||
targetParent.objectCount = mergedChildren.length;
|
targetParent.objectCount = mergedChildren.length;
|
||||||
setChildren(targetParent, nextChildren);
|
setChildren(targetParent, nextChildren);
|
||||||
await savePersistedTreeChildren(objectGroupCacheKey(targetParent), nextChildren);
|
if (!options?.searchFilter) {
|
||||||
|
await savePersistedTreeChildren(objectGroupCacheKey(targetParent), nextChildren);
|
||||||
|
}
|
||||||
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
||||||
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
||||||
return;
|
return;
|
||||||
@@ -5890,7 +5896,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
if (!targetParent || !parentEpoch.isCurrent()) return;
|
if (!targetParent || !parentEpoch.isCurrent()) return;
|
||||||
targetParent.objectCount = mergedChildren.length;
|
targetParent.objectCount = mergedChildren.length;
|
||||||
setChildren(targetParent, nextChildren);
|
setChildren(targetParent, nextChildren);
|
||||||
await savePersistedTreeChildren(objectGroupCacheKey(targetParent), nextChildren);
|
if (!options?.searchFilter) {
|
||||||
|
await savePersistedTreeChildren(objectGroupCacheKey(targetParent), nextChildren);
|
||||||
|
}
|
||||||
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
const currentTargetParent = treeNodeLoadRelatedTarget(load, parent);
|
||||||
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
if (currentTargetParent && parentEpoch.isCurrent()) currentTargetParent.isExpanded = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 134 KiB |
@@ -8,19 +8,14 @@
|
|||||||
// for the fuzzy query "erpncs". This test locks in the fixed behavior: the
|
// for the fuzzy query "erpncs". This test locks in the fixed behavior: the
|
||||||
// first search builds the index so the complete table set is searchable.
|
// first search builds the index so the complete table set is searchable.
|
||||||
//
|
//
|
||||||
// Remote searches must stay bounded: every fuzzy match travels
|
// Table-scoped remote searches are paginated at the configured sidebar table
|
||||||
// database → IPC → store → tree rendering, so the result set is capped by
|
// page size, so a wide fuzzy query can still reach alphabetically-late matches
|
||||||
// SIDEBAR_TABLE_SEARCH_RESULT_BUDGET (mirrored from connectionStore.ts).
|
// by loading more instead of being silently truncated to one budget window.
|
||||||
import { createPinia, setActivePinia } from "pinia";
|
import { createPinia, setActivePinia } from "pinia";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { matchSidebarLabel } from "../../apps/desktop/src/lib/sidebar/sidebarSearch.ts";
|
import { matchSidebarLabel } from "../../apps/desktop/src/lib/sidebar/sidebarSearch.ts";
|
||||||
import type { ConnectionConfig, TableInfo, TreeNode } from "@/types/database";
|
import type { ConnectionConfig, TableInfo, TreeNode } from "@/types/database";
|
||||||
|
|
||||||
// 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_TABLE_SEARCH_RESULT_BUDGET = 2000;
|
|
||||||
|
|
||||||
function installLocalStorage() {
|
function installLocalStorage() {
|
||||||
const data = new Map<string, string>();
|
const data = new Map<string, string>();
|
||||||
vi.stubGlobal("localStorage", {
|
vi.stubGlobal("localStorage", {
|
||||||
@@ -202,7 +197,7 @@ describe("sidebar local table search first-search index build (#6190)", () => {
|
|||||||
expect(cached?.map((entry) => entry.name)).toContain("T_Erp_Nc_SuPlan_List");
|
expect(cached?.map((entry) => entry.name)).toContain("T_Erp_Nc_SuPlan_List");
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
it("remote search returns the complete fuzzy result set within the result budget", async () => {
|
it("remote search pages through the complete fuzzy result set", async () => {
|
||||||
const allTables = buildTables();
|
const allTables = buildTables();
|
||||||
const listTables = listTablesFor(allTables);
|
const listTables = listTablesFor(allTables);
|
||||||
const { store, tablesGroup } = await installStore(listTables);
|
const { store, tablesGroup } = await installStore(listTables);
|
||||||
@@ -219,29 +214,40 @@ describe("sidebar local table search first-search index build (#6190)", () => {
|
|||||||
await store.loadObjectGroupChildren(tablesGroup, searchOptions(searchFilter));
|
await store.loadObjectGroupChildren(tablesGroup, searchOptions(searchFilter));
|
||||||
};
|
};
|
||||||
|
|
||||||
// First remote search: the backend receives the result budget as the
|
// The first remote search loads one 500-table page plus a load-more node.
|
||||||
// limit — 4× the page size, comfortably above the 801 fuzzy matches of
|
// The alphabetically-late target is on the next page, so it must not be
|
||||||
// this schema — so the alphabetically-late target is never truncated.
|
// dropped from the first result set.
|
||||||
await search("erpncs");
|
await search("erpncs");
|
||||||
const firstResults = (tablesGroup.children ?? []).map((node) => node.label);
|
let children = tablesGroup.children ?? [];
|
||||||
expect(firstResults).toContain("T_Erp_Nc_SuPlan_List");
|
expect(children).toHaveLength(501);
|
||||||
expect(listTables.mock.calls.some((call) => call[3] === "erpncs" && call[4] === SIDEBAR_TABLE_SEARCH_RESULT_BUDGET)).toBe(true);
|
expect(children.at(-1)?.type).toBe("load-more");
|
||||||
|
expect(children.map((node) => node.label)).not.toContain("T_Erp_Nc_SuPlan_List");
|
||||||
|
expect(listTables.mock.calls.some((call) => call[3] === "erpncs" && call[4] === 501 && call[5] === 0)).toBe(true);
|
||||||
|
|
||||||
|
await store.loadMoreObjectGroupChildren(children.at(-1)!, { searchFilter: "erpncs" });
|
||||||
|
children = tablesGroup.children ?? [];
|
||||||
|
expect(children.map((node) => node.label)).toContain("T_Erp_Nc_SuPlan_List");
|
||||||
|
expect(listTables.mock.calls.some((call) => call[3] === "erpncs" && call[4] === 501 && call[5] === 500)).toBe(true);
|
||||||
|
|
||||||
// Repeated searches are order-independent.
|
// Repeated searches are order-independent.
|
||||||
await search("terpncs");
|
await search("terpncs");
|
||||||
expect((tablesGroup.children ?? []).map((node) => node.label)).toContain("T_Erp_Nc_SuPlan_List");
|
expect((tablesGroup.children ?? []).map((node) => node.label)).toContain("T_Erp_Nc_SuPlan_List");
|
||||||
await search("erpncs");
|
await search("erpncs");
|
||||||
|
children = tablesGroup.children ?? [];
|
||||||
|
expect(children.at(-1)?.type).toBe("load-more");
|
||||||
|
await store.loadMoreObjectGroupChildren(children.at(-1)!, { searchFilter: "erpncs" });
|
||||||
expect((tablesGroup.children ?? []).map((node) => node.label)).toContain("T_Erp_Nc_SuPlan_List");
|
expect((tablesGroup.children ?? []).map((node) => node.label)).toContain("T_Erp_Nc_SuPlan_List");
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
it("remote search results never exceed the result budget", async () => {
|
it("remote search results remain paginated for very wide queries", async () => {
|
||||||
// 3000 tables whose names all contain "erpncs": an unbounded search would
|
// 3000 tables whose names all contain "erpncs": pagination keeps every
|
||||||
// return all 3000; the budget caps a single result set at 2000.
|
// loaded page bounded by the configured sidebar table page size.
|
||||||
const allTables: TableInfo[] = [];
|
const allTables: TableInfo[] = [];
|
||||||
for (let i = 0; i < 3000; i++) allTables.push({ name: `ErpNcS${i}`, table_type: "TABLE", comment: null });
|
for (let i = 0; i < 3000; i++) allTables.push({ name: `ErpNcS${i}`, table_type: "TABLE", comment: null });
|
||||||
const listTables = listTablesFor(allTables);
|
const listTables = listTablesFor(allTables);
|
||||||
const { store, tablesGroup } = await installStore(listTables);
|
const { store, tablesGroup } = await installStore(listTables);
|
||||||
|
|
||||||
|
store.setSidebarTableSearchQuery(tablesGroup.id, "erpncs");
|
||||||
await store.loadObjectGroupChildren(tablesGroup, {
|
await store.loadObjectGroupChildren(tablesGroup, {
|
||||||
force: true,
|
force: true,
|
||||||
searchFilter: "erpncs",
|
searchFilter: "erpncs",
|
||||||
@@ -250,8 +256,14 @@ describe("sidebar local table search first-search index build (#6190)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const children = tablesGroup.children ?? [];
|
const children = tablesGroup.children ?? [];
|
||||||
expect(children.length).toBeLessThanOrEqual(SIDEBAR_TABLE_SEARCH_RESULT_BUDGET);
|
expect(children).toHaveLength(501);
|
||||||
expect(listTables.mock.calls.some((call) => call[3] === "erpncs" && call[4] === SIDEBAR_TABLE_SEARCH_RESULT_BUDGET)).toBe(true);
|
expect(children.at(-1)?.type).toBe("load-more");
|
||||||
|
expect(listTables.mock.calls.some((call) => call[3] === "erpncs" && call[4] === 501 && call[5] === 0)).toBe(true);
|
||||||
|
|
||||||
|
await store.loadMoreObjectGroupChildren(children.at(-1)!, { searchFilter: "erpncs" });
|
||||||
|
const loadedRows = (tablesGroup.children ?? []).filter((node) => node.type !== "load-more");
|
||||||
|
expect(loadedRows).toHaveLength(1000);
|
||||||
|
expect((tablesGroup.children ?? []).at(-1)?.type).toBe("load-more");
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
it("an empty (cleared) query never issues a remote fuzzy search", async () => {
|
it("an empty (cleared) query never issues a remote fuzzy search", async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user