Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

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

t8y2e4246d204c76
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vue
index 1ce34a6cea..62686e38bc 100644
--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue
+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue
@@ -46,11 +46,34 @@ watch(
searchTimer = window.setTimeout(() => {
deferredSearchQuery.value = normalized;
- }, 120);
+ }, 300);
},
{ flush: "sync" },
);
+watch(deferredSearchQuery, (newQuery) => {
+ store.sidebarSearchQuery = newQuery;
+ const tasks: Promise<void>[] = [];
+ for (const root of store.treeNodes) {
+ findExpandedTableParents(root, tasks);
+ }
+ Promise.all(tasks).catch(() => {});
+});
+
+function findExpandedTableParents(node: TreeNode, tasks: Promise<void>[]) {
+ if (node.isExpanded && node.connectionId && (node.type === "database" || node.type === "schema")) {
+ const groupTypes = new Set(["group-tables", "group-views", "group-procedures", "group-functions", "group-sequences", "group-packages"]);
+ if (node.children?.some((child) => groupTypes.has(child.type))) {
+ tasks.push(store.loadObjectGroupChildren(node, { force: true }));
+ }
+ }
+ if (node.children) {
+ for (const child of node.children) {
+ findExpandedTableParents(child, tasks);
+ }
+ }
+}
+
const isSearching = computed(() => !!deferredSearchQuery.value);
const isFiltering = computed(() => !!searchQuery.value.trim() || hasSearchScopeFilter.value);
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index bfb7888564..56e6a2bcdc 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -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);