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。

perf(grid): memoize virtual rows

t8y2efc68c42445b
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 583c3ab7d3..ff20d5ebbd 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -382,6 +382,24 @@ const savedCustomFormatters = computed(() => {
);
});
+const columnFormatterMemoKey = computed(() =>
+ JSON.stringify({
+ columns: props.result.columns,
+ columnFormatters: settingsStore.editorSettings.columnFormatters,
+ customColumnFormatters: settingsStore.editorSettings.customColumnFormatters,
+ }),
+);
+
+const cellEditabilityMemoKey = computed(() =>
+ JSON.stringify({
+ editable: props.editable,
+ canEditExistingRows: canEditExistingRows.value,
+ databaseType: props.databaseType,
+ sourceColumns: props.sourceColumns,
+ tableColumns: props.tableMeta?.columns.map((column) => [column.name, column.data_type]),
+ }),
+);
+
function localFilterKey(value: CellValue): string {
if (value === null) return "__dbx_null__";
if (typeof value === "boolean") return `bool:${value}`;
@@ -1629,6 +1647,24 @@ const searchMatchSet = computed(() => {
return set;
});
+const searchRowMemoKeys = computed(() => {
+ const rows = new Map<number, string[]>();
+ for (const match of searchMatches.value) {
+ const row = rows.get(match.displayRow) ?? [];
+ row.push(String(match.col));
+ rows.set(match.displayRow, row);
+ }
+
+ const current = searchMatches.value[currentMatchIndex.value];
+ if (current) {
+ const row = rows.get(current.displayRow) ?? [];
+ row.push(`current:${current.col}`);
+ rows.set(current.displayRow, row);
+ }
+
+ return new Map([...rows].map(([row, parts]) => [row, parts.join("|")]));
+});
+
watch(searchMatches, (matches) => {
currentMatchIndex.value = matches.length > 0 ? 0 : -1;
});
@@ -1644,6 +1680,10 @@ function cellIsCurrentMatch(displayRow: number, col: number): boolean {
return m.displayRow === displayRow && m.col === col;
}
+function rowSearchMemoKey(index: number): string {
+ return searchRowMemoKeys.value.get(index) ?? "";
+}
+
function navigateMatch(delta: number) {
const total = searchMatches.value.length;
if (total === 0) return;
@@ -1801,6 +1841,36 @@ function isRowActive(index: number): boolean {
return index >= range.startRow && index <= range.endRow;
}
+function rowSelectionMemoKey(item: RowItem, index: number): string {
+ const rowSelected = selectedRowIds.value.has(item.id) ? "row" : "";
+ const range = selectedRange.value;
+ if (!range || index < range.startRow || index > range.endRow) return rowSelected;
+ return `${rowSelected}|cells:${range.startCol}:${range.endCol}`;
+}
+
+function rowHoverMemoKey(index: number): string {
+ return hoveredDetailCell.value?.rowIndex === index ? String(hoveredDetailCell.value.col) : "";
+}
+
+function rowEditMemoKey(item: RowItem): string {
+ return editingCell.value?.rowId === item.id ? `${editingCell.value.col}:${editValue.value}` : "";
+}
+
+function rowRenderMemoDeps(item: RowItem, index: number) {
+ return [
+ item.data,
+ item.status,
+ item.isDirtyCol,
+ rowSelectionMemoKey(item, index),
+ rowSearchMemoKey(index),
+ rowHoverMemoKey(index),
+ rowEditMemoKey(item),
+ visibleColumnIndexes.value,
+ columnFormatterMemoKey.value,
+ cellEditabilityMemoKey.value,
+ ];
+}
+
const contextRowItem = computed(() => (contextCell.value ? getRowItem(contextCell.value.rowId) : undefined));
const contextColumn = computed(() => {
if (!contextCell.value || contextCell.value.col < 0) return null;
@@ -4032,6 +4102,7 @@ defineExpose({
<template #default="{ item, index }">
<div
class="flex text-xs border-b border-border"
+ v-memo="rowRenderMemoDeps(item, index)"
:class="{
'bg-destructive/5 opacity-70': item.isDeleted,
'bg-primary/5': item.isNew && !isRowActive(index),
diff --git a/packages/app-tests/dataGridVuePerformance.test.ts b/packages/app-tests/dataGridVuePerformance.test.ts
new file mode 100644
index 0000000000..4363dedaa6
--- /dev/null
+++ b/packages/app-tests/dataGridVuePerformance.test.ts
@@ -0,0 +1,14 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+const source = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");
+
+test("data grid memoizes virtual rows with render-affecting dependencies", () => {
+ assert.match(source, /function rowRenderMemoDeps\(item: RowItem, index: number\)/);
+ assert.match(source, /function rowSelectionMemoKey\(item: RowItem, index: number\)/);
+ assert.match(source, /function rowSearchMemoKey\(index: number\)/);
+ assert.match(source, /function rowHoverMemoKey\(index: number\)/);
+ assert.match(source, /const columnFormatterMemoKey = computed/);
+ assert.match(source, /v-memo="rowRenderMemoDeps\(item, index\)"/);
+});