feat(sidebar): pass search as filter to listTables, debounce 300ms

This commit is contained in:
t8y2 committed 2026-06-15 23:45:34 +08:00
1 parent cce7fcc600
commit e4246d204c
2 files changed
+37 -7

No files matched your search

+13 -6
View File
@@ -109,6 +109,7 @@ export const useConnectionStore = defineStore("connection", () => {
const completionDatabasesCache = ref<Record<string, string[]>>({});
const elasticsearchCompletionIndicesCache = ref<Record<string, string[]>>({});
const schemaListCache = ref<Record<string, string[]>>({});
const sidebarSearchQuery = ref("");
const completionTableIndex = new Map<string, { touched: number; tables: SqlCompletionTable[] }>();
const completionObjectIndex = new Map<string, { touched: number; objects: SqlCompletionObject[] }>();
const completionColumnIndex = new Map<string, { touched: number; columns: SqlCompletionColumn[] }>();
@@ -455,9 +456,12 @@ export const useConnectionStore = defineStore("connection", () => {
if (!options.node.connectionId || !options.node.database) {
return { children: [], objectCount: 0, hasMore: false, nextOffset: options.offset };
}
const fetchLimit = options.pageSize + 1;
const tables = await api.listTables(options.node.connectionId, options.node.database, options.querySchema, undefined, fetchLimit, options.offset);
const hasMore = tables.length > options.pageSize;
const searchFilter = sidebarSearchQuery.value || undefined;
// When searching, fetch all matching tables (no pagination) — backend filter
// already narrows the result set, so client-side filtering is not needed.
const fetchLimit = searchFilter ? undefined : options.pageSize + 1;
const tables = await api.listTables(options.node.connectionId, options.node.database, options.querySchema, searchFilter, fetchLimit, searchFilter ? undefined : options.offset);
const hasMore = searchFilter ? false : tables.length > options.pageSize;
const pageTables = hasMore ? tables.slice(0, options.pageSize) : tables;
const objects = mergeTableInfosIntoObjects([], pageTables, options.effectiveSchema);
const visibleObjectCount = objects.filter((object) => options.objectTypes.includes(normalizedObjectTreeKind(object.object_type))).length;
@@ -1272,7 +1276,7 @@ export const useConnectionStore = defineStore("connection", () => {
const querySchema = connectionObjectTreeQuerySchema(config, node.database, node.schema);
const effectiveSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);
const cacheKey = objectGroupCacheKey(node);
if (!options?.force) {
if (!options?.force && !sidebarSearchQuery.value) {
const cached = await loadPersistedTreeChildren(node, cacheKey);
if (cached.hit) {
if (cached.isStale) refreshStaleTreeNode(node);
@@ -1292,7 +1296,7 @@ export const useConnectionStore = defineStore("connection", () => {
offset: 0,
pageSize: SIDEBAR_OBJECT_GROUP_PAGE_SIZE,
});
children = page.hasMore ? [...page.children, buildLoadMoreNode(node, page.nextOffset, SIDEBAR_OBJECT_GROUP_PAGE_SIZE)] : page.children;
children = page.hasMore && !sidebarSearchQuery.value ? [...page.children, buildLoadMoreNode(node, page.nextOffset, SIDEBAR_OBJECT_GROUP_PAGE_SIZE)] : page.children;
node.objectCount = page.objectCount;
} else {
const objects = await api.listObjects(node.connectionId, node.database, querySchema, objectTypes);
@@ -1306,7 +1310,9 @@ export const useConnectionStore = defineStore("connection", () => {
node.objectCount = children.length;
}
setChildren(node, children);
await savePersistedTreeChildren(cacheKey, children);
if (!sidebarSearchQuery.value) {
await savePersistedTreeChildren(cacheKey, children);
}
node.isExpanded = true;
} catch (e) {
recordMetadataLoadError(node.connectionId, e);
@@ -2748,6 +2754,7 @@ export const useConnectionStore = defineStore("connection", () => {
fieldLineageSource,
databaseSearchSource,
databaseExportSource,
sidebarSearchQuery,
createConnectionGroup(name: string, parentGroupId?: string | null) {
const result = createGroupOp(sidebarLayout.value, name, parentGroupId);
updateLayoutAndRebuild(result.layout);