An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve large CSV pasting into databases https://github.com/siyuan-note/siyuan/issues/10767
Daniel4a5cd5b7d695
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scssindex 815187cd11..d5da0d5a92 100644--- a/app/src/assets/scss/business/_av.scss+++ b/app/src/assets/scss/business/_av.scss@@ -82,6 +82,33 @@}}+ &--paste-loading {+ min-height: 194px;+ position: relative;+ }++ &__paste-skeleton {+ background-color: var(--b3-theme-background);+ border-radius: var(--b3-border-radius);+ cursor: wait;+ inset: 0;+ overflow: hidden;+ position: absolute;+ z-index: 5;++ .av__row {+ background-color: var(--b3-theme-background);+ min-height: 38px;+ }++ .av__cell {+ align-items: center;+ display: flex;+ flex-shrink: 0;+ padding: 8px;+ }+ }+&__header {position: relative;diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.tsindex 59c02ec58a..f05e68fe46 100644--- a/app/src/protyle/render/av/cell.ts+++ b/app/src/protyle/render/av/cell.ts@@ -40,22 +40,7 @@ import {export {cellValueIsEmpty} from "./cellValue";const renderCellURL = (urlContent: string) => {- let host = urlContent;- let suffix = "";- try {- const urlObj = new URL(urlContent);- if (urlObj.protocol.startsWith("http")) {- host = urlObj.host;- suffix = urlObj.href.replace(urlObj.origin, "");- if (suffix.length > 12) {- suffix = suffix.substring(0, 4) + "..." + suffix.substring(suffix.length - 6);- }- }- } catch (e) {- // 不是 url 地址- }- // host 统一在输出处转义,避免非 http 协议(如 asd:<img...>)绕过 https://github.com/siyuan-note/siyuan/issues/9291- return `<span class="av__celltext av__celltext--url" data-type="url" data-href="${escapeAttr(urlContent)}"><span>${Lute.EscapeHTMLStr(host)}</span><span class="ft__on-surface">${Lute.EscapeHTMLStr(suffix)}</span></span>`;+ return `<span class="av__celltext av__celltext--url" data-type="url" data-href="${escapeAttr(urlContent)}">${Lute.EscapeHTMLStr(urlContent)}</span>`;};export const getCellText = (cellElement: HTMLElement | false) => {@@ -750,7 +735,7 @@ const updateCellValueByInput = (protyle: IProtyle, type: TAVCol, blockElement: Hexport const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLElement, value?: any,cElements?: HTMLElement[], columns?: IAVColumn[], html?: string, getOperations = false,forceOperation = false, replaceSelectValues = false,- stableCells?: IAVSelectedCell[]) => {+ stableCells?: IAVSelectedCell[], updateElements = true) => {const doOperations: IOperation[] = [];const undoOperations: IOperation[] = [];@@ -824,21 +809,23 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLElemeif (elementIndex === 0 && item && batchMode !== "replace") {batchDisplayValue = getAVBatchDisplayValue(item, renderedOldValue);}- const nextSource = sources[elementIndex + 1];- const sameNextRow = nextSource && (source.selectedCell ?- nextSource.selectedCell?.rowID === rowID :- Boolean(item?.nextElementSibling && item.nextElementSibling === nextSource.element));- const cellText = item ? getCellText(item) :- getCellValueText(oldValue, source.selectedCell?.column, source.selectedCell?.rowIndex);- text += cellText + (sameNextRow ? "\t" : "\n\n");- const previousSource = sources[elementIndex - 1];- const samePreviousRow = previousSource && (source.selectedCell ?- previousSource.selectedCell?.rowID === rowID :- previousSource.element === item?.previousElementSibling);- if (!samePreviousRow) {- json.push([]);+ if (!getOperations) {+ const nextSource = sources[elementIndex + 1];+ const sameNextRow = nextSource && (source.selectedCell ?+ nextSource.selectedCell?.rowID === rowID :+ Boolean(item?.nextElementSibling && item.nextElementSibling === nextSource.element));+ const cellText = item ? getCellText(item) :+ getCellValueText(oldValue, source.selectedCell?.column, source.selectedCell?.rowIndex);+ text += cellText + (sameNextRow ? "\t" : "\n\n");+ const previousSource = sources[elementIndex - 1];+ const samePreviousRow = previousSource && (source.selectedCell ?+ previousSource.selectedCell?.rowID === rowID :+ previousSource.element === item?.previousElementSibling);+ if (!samePreviousRow) {+ json.push([]);+ }+ json[json.length - 1].push(oldValue);}- json[json.length - 1].push(oldValue);if (readonly || !cellId) {continue;}@@ -988,14 +975,16 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLElemerowID,data: oldValue});- if (isCustomAttr && item) {- item.innerHTML = genAVValueHTML(cellValue, column?.dateFormat);- item.parentElement.dataset.empty = cellValueIsEmpty(cellValue).toString();- } else if (item) {- updateAttrViewCellAnimation(item, cellValue);+ if (updateElements) {+ if (isCustomAttr && item) {+ item.innerHTML = genAVValueHTML(cellValue, column?.dateFormat);+ item.parentElement.dataset.empty = cellValueIsEmpty(cellValue).toString();+ } else if (item) {+ updateAttrViewCellAnimation(item, cellValue);+ }+ updateAttrViewCellInOtherElements(protyle, avID, rowID, colId, cellValue, item);+ updateAVSelectedCellValue(nodeElement, rowID, colId, cellValue);}- updateAttrViewCellInOtherElements(protyle, avID, rowID, colId, cellValue, item);- updateAVSelectedCellValue(nodeElement, rowID, colId, cellValue);}}if (nextBatchDisplayValue) {diff --git a/app/src/protyle/render/av/paste.test.ts b/app/src/protyle/render/av/paste.test.tsindex 3a193d9102..6e60130c6b 100644--- a/app/src/protyle/render/av/paste.test.ts+++ b/app/src/protyle/render/av/paste.test.ts@@ -2,8 +2,11 @@ import {describe, it} from "node:test";import * as assert from "node:assert/strict";import {getAVPasteMatrixWidth,+ getAVPasteColumnWidth,getUniqueAVPasteColumnName,inferAVPasteColumnType,+ isAVPasteHeaderCandidate,+ shouldShowAVPasteSkeleton,} from "./paste";describe("inferAVPasteColumnType", () => {@@ -24,6 +27,29 @@ describe("inferAVPasteColumnType", () => {assert.equal(inferAVPasteColumnType(["", " "]), "text");assert.equal(inferAVPasteColumnType(["1", "value"]), "text");});++ it("infers complete HTTP URLs conservatively", () => {+ assert.equal(inferAVPasteColumnType([+ "https://github.com/siyuan-note/siyuan/issues/10767",+ "http://localhost:6806/path?key=value#heading",+ ]), "url");+ assert.equal(inferAVPasteColumnType(["www.example.com", "https://example.com"]), "text");+ assert.equal(inferAVPasteColumnType(["/relative/path", "https://example.com"]), "text");+ assert.equal(inferAVPasteColumnType(["mailto:[email protected]"]), "text");+ });++ it("infers repeated low-cardinality values as single select", () => {+ assert.equal(inferAVPasteColumnType(["P1", "P2", "P1", "P3", "P2", "P1"]), "select");+ assert.equal(inferAVPasteColumnType(["高", "中", "低", "高", "中", "高"]), "select");+ assert.equal(inferAVPasteColumnType(["P1", "P2", "P1"]), "text");+ assert.equal(inferAVPasteColumnType(["#1", "#2", "#3", "#4", "#5", "#6"]), "text");+ assert.equal(inferAVPasteColumnType([+ "This is a repeated paragraph that is too long to use as a single-select option value",+ "This is a repeated paragraph that is too long to use as a single-select option value",+ "Another repeated paragraph that is also too long to use as a single-select option",+ "Another repeated paragraph that is also too long to use as a single-select option",+ ]), "text");+ });});describe("AV paste matrix helpers", () => {@@ -37,4 +63,27 @@ describe("AV paste matrix helpers", () => {assert.equal(getUniqueAVPasteColumnName("Text", usedNames), "Text 3");assert.equal(getUniqueAVPasteColumnName("Other", usedNames), "Other");});++ it("recognizes spreadsheet tables without semantic header cells", () => {+ assert.equal(isAVPasteHeaderCandidate([["Name", "Age"], ["Alice", "20"]], false), true);+ assert.equal(isAVPasteHeaderCandidate([["Name"]], true), true);+ assert.equal(isAVPasteHeaderCandidate([["Alice", "20"]], false), false);+ assert.equal(isAVPasteHeaderCandidate([["Alice"], ["Bob"]], false), false);+ });++ it("shows a skeleton only for large paste matrices", () => {+ assert.equal(shouldShowAVPasteSkeleton(Array.from({length: 10}, () => Array(10))), true);+ assert.equal(shouldShowAVPasteSkeleton(Array.from({length: 9}, () => Array(10))), false);+ assert.equal(shouldShowAVPasteSkeleton([Array(100)]), true);+ });++ it("calculates compact widths from measured content", () => {+ const measureText = (value: string) => value.length * 10;+ assert.equal(getAVPasteColumnWidth("优先级", "select", ["P1", "P2", "P3"], measureText), "72px");+ assert.equal(getAVPasteColumnWidth(+ "URL", "url", ["https://github.com/siyuan-note/siyuan/issues/10767"], measureText), "480px");+ assert.equal(getAVPasteColumnWidth("日期", "date", ["2026-07-30"], measureText), "120px");+ assert.equal(getAVPasteColumnWidth(+ "标题", "text", ["A very long title that should not make the field excessively wide"], measureText), "480px");+ });});diff --git a/app/src/protyle/render/av/paste.ts b/app/src/protyle/render/av/paste.tsindex 4080751bc4..f1af62fe9a 100644--- a/app/src/protyle/render/av/paste.ts+++ b/app/src/protyle/render/av/paste.ts@@ -35,6 +35,23 @@ const isFullDate = (value: string) => {return hour < 24 && minute < 60 && second < 60;};+const isURL = (value: string) => {+ try {+ const url = new URL(value.trim());+ return url.protocol === "http:" || url.protocol === "https:";+ } catch (e) {+ return false;+ }+};++const isSingleSelect = (values: string[]) => {+ if (values.length < 4 || values.some(value => value.length > 64 || /[\r\n]/.test(value))) {+ return false;+ }+ const optionCount = new Set(values).size;+ return optionCount > 1 && optionCount <= 20 && optionCount / values.length <= 0.5;+};+export const inferAVPasteColumnType = (values: string[]): TAVCol => {const nonEmptyValues = values.map(value => value.trim()).filter(Boolean);if (nonEmptyValues.length === 0) {@@ -46,6 +63,12 @@ export const inferAVPasteColumnType = (values: string[]): TAVCol => {if (nonEmptyValues.every(isFullDate)) {return "date";}+ if (nonEmptyValues.every(isURL)) {+ return "url";+ }+ if (isSingleSelect(nonEmptyValues)) {+ return "select";+ }return "text";};@@ -53,6 +76,80 @@ export const getAVPasteMatrixWidth = (rows: unknown[][], header?: string[]) => {return Math.max(header?.length || 0, ...rows.map(row => row.length), 0);};+export const shouldShowAVPasteSkeleton = (rows: unknown[][]) => {+ return rows.reduce((count, row) => count + row.length, 0) >= 100;+};++const getEstimatedTextWidth = (value: string) => {+ return Array.from(value.trim().replace(/[\r\n]+/g, " ")).reduce((width, character) => {+ if (/[\u2E80-\u9FFF\uAC00-\uD7AF]/u.test(character)) {+ return width + 14;+ }+ if (/\s/u.test(character)) {+ return width + 4;+ }+ if (/[A-ZMW@#%&]/u.test(character)) {+ return width + 9;+ }+ return width + 7;+ }, 0);+};++export const getAVPasteTextMeasurer = (blockElement: HTMLElement) => {+ const canvas = document.createElement("canvas");+ const context = canvas.getContext("2d");+ const cellElement = blockElement.querySelector<HTMLElement>(".av__cell");+ if (!context || !cellElement) {+ return getEstimatedTextWidth;+ }+ const style = getComputedStyle(cellElement);+ context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;+ return (value: string) => context.measureText(value.trim().replace(/[\r\n]+/g, " ")).width;+};++export const getAVPasteColumnWidth = (name: string, type: TAVCol, values: string[],+ measureText = getEstimatedTextWidth) => {+ const headerWidth = measureText(name) + 42;+ const contentPadding = type === "select" ? 32 : 20;+ const contentWidth = values.reduce((width, value) => Math.max(width, measureText(value) + contentPadding), 0);+ return `${Math.ceil(Math.min(480, Math.max(64, headerWidth, contentWidth)))}px`;+};++export const showAVPasteSkeleton = (blockElement: HTMLElement, columnCount: number) => {+ if (blockElement.querySelector(".av__paste-skeleton")) {+ return false;+ }+ const skeletonElement = document.createElement("div");+ skeletonElement.className = "av__paste-skeleton";+ skeletonElement.setAttribute("role", "status");+ skeletonElement.setAttribute("aria-label", window.siyuan.languages.loading);+ const visibleColumnCount = Math.min(Math.max(columnCount, 2), 6);+ let html = "";+ for (let rowIndex = 0; rowIndex < 5; rowIndex++) {+ html += '<div class="av__row"><div style="width: 24px;flex-shrink: 0"></div>';+ for (let columnIndex = 0; columnIndex < visibleColumnCount; columnIndex++) {+ const pulseWidth = 45 + (rowIndex * 17 + columnIndex * 13) % 45;+ html += `<div class="av__cell" style="width: 200px"><span class="av__pulse" style="width: ${pulseWidth}%"></span></div>`;+ }+ html += "</div>";+ }+ skeletonElement.innerHTML = html;+ blockElement.classList.add("av--paste-loading");+ blockElement.setAttribute("aria-busy", "true");+ blockElement.append(skeletonElement);+ return true;+};++export const removeAVPasteSkeleton = (blockElement: HTMLElement) => {+ blockElement.querySelector(".av__paste-skeleton")?.remove();+ blockElement.classList.remove("av--paste-loading");+ blockElement.removeAttribute("aria-busy");+};++export const isAVPasteHeaderCandidate = (rows: unknown[][], hasSemanticHeader: boolean) => {+ return hasSemanticHeader || (rows.length > 1 && getAVPasteMatrixWidth(rows) > 1);+};+export const getUniqueAVPasteColumnName = (baseName: string, usedNames: Set<string>) => {if (!usedNames.has(baseName)) {return baseName;diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.tsindex a42d6c12d8..3c186010b7 100644--- a/app/src/protyle/render/av/render.ts+++ b/app/src/protyle/render/av/render.ts@@ -35,6 +35,7 @@ import {serializeAVViewPageSizes,setAVVisibleViewIDs} from "./viewVisibility";+import {removeAVPasteSkeleton} from "./paste";interface IIds {groupId: string,@@ -1070,6 +1071,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {openMenuPanel({protyle, blockElement: item, type: "config"});}}+ removeAVPasteSkeleton(item);item.removeAttribute("data-loading");});});diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex d3202f420c..27d08d561c 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -39,9 +39,15 @@ import {setFold} from "./blockFold";import {removeFoldHeading} from "./heading";import {AV_PASTE_READONLY_TYPES,+ getAVPasteColumnWidth,getAVPasteMatrixWidth,+ getAVPasteTextMeasurer,getUniqueAVPasteColumnName,inferAVPasteColumnType,+ isAVPasteHeaderCandidate,+ removeAVPasteSkeleton,+ shouldShowAVPasteSkeleton,+ showAVPasteSkeleton,} from "../render/av/paste";import {Dialog} from "../../dialog";import {isMobile} from "../../util/functions";@@ -327,6 +333,8 @@ const pasteAVMatrix = async (options: {const schemaDoOperations: IOperation[] = [];const schemaUndoOperations: IOperation[] = [];+ const widthDoOperations: IOperation[] = [];+ const widthUndoOperations: IOperation[] = [];const newColumnUndoOperations: IOperation[] = [];const inferableKeyIDs = new Set<string>(response.data?.inferableKeyIDs || []);const visibleColumns = view.columns.filter(column => !column.hidden);@@ -338,6 +346,7 @@ const pasteAVMatrix = async (options: {const usedNames = new Set(options.columns.map(column => column.name));const changedCellColumnIDs = new Set<string>();const targetColumns: IAVPasteTargetColumn[] = [];+ const measureText = getAVPasteTextMeasurer(options.blockElement);let previousColumnID = visibleColumns[visibleColumns.length - 1].id;for (let sourceIndex = 0; sourceIndex < sourceWidth; sourceIndex++) {@@ -354,9 +363,13 @@ const pasteAVMatrix = async (options: {currentColumn.type !== "block" && !readonly? inferredType: currentColumn.type;+ const compactWidth = options.header && (!oldColumn.width || oldColumn.width === "200px")+ ? getAVPasteColumnWidth(nextName, nextType, sourceValues, measureText)+ : oldColumn.width;const typeChanged = oldColumn.type !== nextType;currentColumn.name = nextName;currentColumn.type = nextType;+ currentColumn.width = compactWidth;if (typeChanged && nextType === "date") {currentColumn.date = {autoFillNow: false,@@ -367,6 +380,7 @@ const pasteAVMatrix = async (options: {if (valueColumn) {valueColumn.name = nextName;valueColumn.type = nextType;+ valueColumn.width = compactWidth;if (typeChanged && nextType === "date") {valueColumn.date = currentColumn.date;}@@ -388,6 +402,23 @@ const pasteAVMatrix = async (options: {type: oldColumn.type,});}+ if (compactWidth && oldColumn.width !== compactWidth) {+ const widthOperation = {+ action: "setAttrViewColWidth" as const,+ id: currentColumn.id,+ avID: options.blockElement.dataset.avId,+ blockID: options.blockElement.dataset.nodeId,+ viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "",+ };+ widthDoOperations.push({+ ...widthOperation,+ data: compactWidth,+ });+ widthUndoOperations.push({+ ...widthOperation,+ data: oldColumn.width || "200px",+ });+ }if (typeChanged) {const columnIndex = view.columns.findIndex(column => column.id === currentColumn.id);rows.forEach(row => {@@ -404,6 +435,7 @@ const pasteAVMatrix = async (options: {const name = headerName ? headerName : getUniqueAVPasteColumnName(baseName, usedNames);const type = options.header ? inferredType : "text";const column = genAVPasteColumn(id, name, type);+ column.width = getAVPasteColumnWidth(name, type, sourceValues, measureText);const previousIndex = view.columns.findIndex(item => item.id === previousColumnID);view.columns.splice(previousIndex + 1, 0, column);rows.forEach(row => {@@ -420,6 +452,14 @@ const pasteAVMatrix = async (options: {id,previousID: previousColumnID,});+ widthDoOperations.push({+ action: "setAttrViewColWidth",+ id,+ avID: options.blockElement.dataset.avId,+ data: column.width,+ blockID: options.blockElement.dataset.nodeId,+ viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "",+ });newColumnUndoOperations.unshift({action: "removeAttrViewCol",id,@@ -509,7 +549,7 @@ const pasteAVMatrix = async (options: {const isNewRow = newRowIDSet.has(pasteRows[i].id);const operations = await updateCellsValue(options.protyle, options.blockElement, options.values[i][j],[cellElement], options.columns, options.cellHTML?.[i]?.[j] || options.html,- true, isNewRow || targetColumn.isNew || targetColumn.typeChanged, true);+ true, isNewRow || targetColumn.isNew || targetColumn.typeChanged, true, undefined, false);if (operations.doOperations.length > 0) {cellDoOperations.push(...operations.doOperations);const hasCellUpdate = operations.doOperations.some(operation => operation.action === "updateAttrViewCell");@@ -539,13 +579,14 @@ const pasteAVMatrix = async (options: {removePlaceholderRows(options.blockElement);}- const doOperations = [...schemaDoOperations, ...rowDoOperations, ...cellDoOperations];+ const doOperations = [...schemaDoOperations, ...widthDoOperations, ...rowDoOperations, ...cellDoOperations];if (doOperations.length === 0) {return;}const undoOperations = [...cellUndoOperations,...rowUndoOperations,+ ...widthUndoOperations.reverse(),...schemaUndoOperations.reverse(),...newColumnUndoOperations,];@@ -560,6 +601,30 @@ const pasteAVMatrix = async (options: {data: options.blockElement.getAttribute("updated"),});transaction(options.protyle, doOperations, undoOperations);+ return true;+};++const pasteAVMatrixWithSkeleton = async (options: Parameters<typeof pasteAVMatrix>[0]) => {+ const showSkeleton = shouldShowAVPasteSkeleton(options.values) &&+ showAVPasteSkeleton(options.blockElement, getAVPasteMatrixWidth(options.values, options.header));+ if (showSkeleton) {+ await new Promise<void>((resolve) => {+ requestAnimationFrame(() => resolve());+ });+ }+ try {+ const submitted = await pasteAVMatrix(options);+ if (showSkeleton && !submitted) {+ removeAVPasteSkeleton(options.blockElement);+ } else if (showSkeleton) {+ window.setTimeout(() => removeAVPasteSkeleton(options.blockElement), 30000);+ }+ } catch (error) {+ if (showSkeleton) {+ removeAVPasteSkeleton(options.blockElement);+ }+ throw error;+ }};const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: HTMLElement) => {@@ -598,6 +663,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:cellHTML.push(rowHTML);}});+ headerCandidate = isAVPasteHeaderCandidate(values, headerCandidate);}const avID = blockElement.dataset.avId;fetchPost("/api/av/getAttributeViewKeysByAvID", {avID}, async (response) => {@@ -614,7 +680,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:const useHeader = headerCandidate ? await confirmAVPasteHeader() : false;const header = useHeader ?values[0].map(value => typeof value === "string" ? value : "") : undefined;- await pasteAVMatrix({+ await pasteAVMatrixWithSkeleton({values: useHeader ? values.slice(1) : values,protyle,blockElement,@@ -675,7 +741,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:updateCellsValue(protyle, blockElement as HTMLElement, normalizedText,selectedCells.length > 0 ? undefined : cellElements, columns, html);} else {- await pasteAVMatrix({+ await pasteAVMatrixWithSkeleton({values: textJSON,protyle,blockElement,@@ -690,7 +756,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:if (textJSON.length === 1 && textJSON[0].length === 1) {updateCellsValue(protyle, blockElement as HTMLElement, normalizedText, undefined, columns, html);} else {- await pasteAVMatrix({+ await pasteAVMatrixWithSkeleton({values: textJSON,protyle,blockElement,diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 70bf2a8089..193bbf322b 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -7206,6 +7206,25 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {return}+func (tx *Transaction) doBatchUpdateAttrViewCells(operations []*Operation) (ret *TxErr) {+ attrView, err := av.ParseAttributeView(operations[0].AvID)+ if err != nil {+ return &TxErr{code: TxErrHandleAttributeView, id: operations[0].AvID, msg: err.Error()}+ }++ for _, operation := range operations {+ if _, err = updateAttributeViewValue(tx, attrView, operation.KeyID, operation.RowID, operation.Data, false); err != nil {+ return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}+ }+ }+ regenAttrViewGroups(attrView)+ if err = av.SaveAttributeView(attrView); err != nil {+ return &TxErr{code: TxErrHandleAttributeView, id: attrView.ID, msg: err.Error()}+ }+ refreshRelatedSrcAvs(attrView.ID, tx)+ return+}+func BatchUpdateAttributeViewCells(tx *Transaction, avID string, values []any) (err error) {attrView, err := av.ParseAttributeView(avID)if err != nil {@@ -7228,11 +7247,16 @@ func BatchUpdateAttributeViewCells(tx *Transaction, avID string, values []any) (return}valueData := v["value"]- _, err = updateAttributeViewValue(tx, attrView, keyID, itemID, valueData)+ _, err = updateAttributeViewValue(tx, attrView, keyID, itemID, valueData, false)if err != nil {return}}+ regenAttrViewGroups(attrView)+ if err = av.SaveAttributeView(attrView); err != nil {+ return+ }+ refreshRelatedSrcAvs(avID, tx)return}@@ -7242,14 +7266,14 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, itemID string, valueDreturn}- val, err = updateAttributeViewValue(tx, attrView, keyID, itemID, valueData)+ val, err = updateAttributeViewValue(tx, attrView, keyID, itemID, valueData, true)if nil != err {return}return}-func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID, itemID string, valueData any) (val *av.Value, err error) {+func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID, itemID string, valueData any, save bool) (val *av.Value, err error) {avID := attrView.IDvar blockVal *av.Valuefor _, kv := range attrView.KeyValues {@@ -7433,15 +7457,19 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyIDupdateTwoWayRelationDestAttrView(attrView, key, val, relationChangeMode, oldRelationBlockIDs)}- regenAttrViewGroups(attrView)- if err = av.SaveAttributeView(attrView); nil != err {- return+ if save {+ regenAttrViewGroups(attrView)+ if err = av.SaveAttributeView(attrView); nil != err {+ return+ }}if 0 != relationChangeMode && nil != key && nil != key.Relation && "" != key.Relation.AvID && key.Relation.AvID != avID {ReloadAttrView(key.Relation.AvID)}- refreshRelatedSrcAvs(avID, tx)+ if save {+ refreshRelatedSrcAvs(avID, tx)+ }return}diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex 296e2f2442..2aed3a2480 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -241,7 +241,8 @@ func performTx(tx *Transaction) (ret *TxErr) {isLargeInsert := tx.processLargeInsert()isLargeDelete := tx.processLargeDelete()if !isLargeInsert {- for _, op := range tx.DoOperations {+ for operationIndex := 0; operationIndex < len(tx.DoOperations); operationIndex++ {+ op := tx.DoOperations[operationIndex]if isLargeDelete && "delete" == op.Action {continue}@@ -325,7 +326,20 @@ func performTx(tx *Transaction) (ret *TxErr) {case "sortAttrViewKey":ret = tx.doSortAttrViewKey(op)case "updateAttrViewCell":- ret = tx.doUpdateAttrViewCell(op)+ operations := []*Operation{op}+ for nextIndex := operationIndex + 1; nextIndex < len(tx.DoOperations); nextIndex++ {+ nextOperation := tx.DoOperations[nextIndex]+ if "updateAttrViewCell" != nextOperation.Action || op.AvID != nextOperation.AvID {+ break+ }+ operations = append(operations, nextOperation)+ }+ if 1 == len(operations) {+ ret = tx.doUpdateAttrViewCell(op)+ } else {+ ret = tx.doBatchUpdateAttrViewCells(operations)+ operationIndex += len(operations) - 1+ }case "updateAttrViewColOptions":ret = tx.doUpdateAttrViewColOptions(op)case "removeAttrViewColOption":