From 36ac36e30de1f5ad618f149f16fa525dc058471b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 2 Dec 2025 11:37:46 +0800 Subject: [PATCH] :zap: Improve database rendering performance after editing https://github.com/siyuan-note/siyuan/issues/16464 Signed-off-by: Daniel <845765@qq.com> --- kernel/model/attribute_view.go | 34 +++++++++++++++++++++++++--------- kernel/model/push_reload.go | 2 +- kernel/model/transaction.go | 18 ++++++++++++++++-- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 5fd975582..d8df81f0e 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -3548,7 +3548,7 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er return } - refreshRelatedSrcAvs(avID) + refreshRelatedSrcAvs(avID, tx) historyDir, err := GetHistoryDir(HistoryOpUpdate) if err != nil { @@ -4688,7 +4688,7 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newNodeI content = util.UnescapeHTML(content) blockVal.Block.Icon, blockVal.Block.Content = icon, content - refreshRelatedSrcAvs(avID) + refreshRelatedSrcAvs(avID, tx) } else { blockVal.Block.ID = "" } @@ -4950,21 +4950,37 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID return } - refreshRelatedSrcAvs(avID) + refreshRelatedSrcAvs(avID, tx) return } -func refreshRelatedSrcAvs(destAvID string) { +func refreshRelatedSrcAvs(destAvID string, tx *Transaction) { relatedAvIDs := av.GetSrcAvIDs(destAvID) + + var tmp []string for _, relatedAvID := range relatedAvIDs { - destAv, _ := av.ParseAttributeView(relatedAvID) - if nil == destAv { + if relatedAvID == destAvID { + // 目标和源相同则跳过 continue } - regenAttrViewGroups(destAv) - av.SaveAttributeView(destAv) - ReloadAttrView(relatedAvID) + tmp = append(tmp, relatedAvID) + } + relatedAvIDs = tmp + + if nil != tx { + tx.relatedAvIDs = append(tx.relatedAvIDs, relatedAvIDs...) + } else { + for _, relatedAvID := range relatedAvIDs { + destAv, _ := av.ParseAttributeView(relatedAvID) + if nil == destAv { + continue + } + + regenAttrViewGroups(destAv) + av.SaveAttributeView(destAv) + ReloadAttrView(relatedAvID) + } } } diff --git a/kernel/model/push_reload.go b/kernel/model/push_reload.go index ea5972432..2a85eb100 100644 --- a/kernel/model/push_reload.go +++ b/kernel/model/push_reload.go @@ -392,7 +392,7 @@ func updateAttributeViewBlockText(updatedDefNodes map[string]*ast.Node) { av.SaveAttributeView(attrView) ReloadAttrView(avID) - refreshRelatedSrcAvs(avID) + refreshRelatedSrcAvs(avID, nil) } } } diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index ba8d44f83..f1473f87b 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -1924,8 +1924,9 @@ type Transaction struct { DoOperations []*Operation `json:"doOperations"` UndoOperations []*Operation `json:"undoOperations"` - trees map[string]*parse.Tree // 事务中变更的树 - nodes map[string]*ast.Node // 事务中变更的节点 + trees map[string]*parse.Tree // 事务中变更的树 + nodes map[string]*ast.Node // 事务中变更的节点 + relatedAvIDs []string // 事务中变更的属性视图 ID isGlobalAssetsInit bool // 是否初始化过全局资源判断 isGlobalAssets bool // 是否属于全局资源 @@ -1968,6 +1969,19 @@ func (tx *Transaction) commit() (err error) { checkUpsertInUserGuide(tree) } refreshDynamicRefTexts(tx.nodes, tx.trees) + + tx.relatedAvIDs = gulu.Str.RemoveDuplicatedElem(tx.relatedAvIDs) + for _, avID := range tx.relatedAvIDs { + destAv, _ := av.ParseAttributeView(avID) + if nil == destAv { + continue + } + + regenAttrViewGroups(destAv) + av.SaveAttributeView(destAv) + ReloadAttrView(avID) + } + IncSync() tx.state.Store(2) tx.m.Unlock()