From f68edb2516c03ca66ff7e103677347a87f87f95a Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sat, 23 May 2026 08:58:18 +0800 Subject: [PATCH] fix(grid): remove virtual row memoization --- apps/desktop/src/components/grid/DataGrid.vue | 103 ++++++------------ crates/dbx-core/src/query_result_sql.rs | 17 +++ crates/dbx-core/src/sql_dialect.rs | 20 ++++ .../app-tests/dataGridRefreshSort.test.ts | 15 +++ .../app-tests/dataGridVuePerformance.test.ts | 11 +- 5 files changed, 89 insertions(+), 77 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 80b1b3e33..f8a5aee8e 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -382,24 +382,6 @@ 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}`; @@ -1407,6 +1389,7 @@ async function lastPage() { interface RowItem { id: number; + displayIndex: number; sourceIndex?: number; newIndex?: number; data: CellValue[]; @@ -1577,7 +1560,7 @@ const sortedRows = computed(() => { const displayItems = computed(() => { const cols = props.result.columns; const rows = props.result.rows; - const items: RowItem[] = sortedRows.value.map((sourceIndex) => { + const items: Omit[] = sortedRows.value.map((sourceIndex) => { const row = rows[sourceIndex]; const dirty = dirtyRows.value.get(sourceIndex); const data = rowDataWithChanges(row, sourceIndex); @@ -1598,7 +1581,9 @@ const displayItems = computed(() => { status: "new", }); }); - return items.filter((item) => matchesRowStatusFilter(item.status, rowStatusFilter.value)); + return items + .filter((item) => matchesRowStatusFilter(item.status, rowStatusFilter.value)) + .map((item, displayIndex) => ({ ...item, displayIndex })); }); watch( @@ -1834,36 +1819,6 @@ 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; @@ -2079,6 +2034,9 @@ function setDetailNull() { function toggleSort(colName: string, colIdx: number) { if (getIsResizing()) return; + orderByInput.value = ""; + currentPage.value = 1; + resetGridVerticalScroll(true); if (sortCol.value === colName && sortColIndex.value === colIdx) { if (sortDir.value === "asc") { sortDir.value = "desc"; @@ -4083,18 +4041,21 @@ defineExpose({ key-field="id" @scroll="onScrollerScroll" > -