🎨 Improve synchronization of database bound blocks when list blocks change https://github.com/siyuan-note/siyuan/issues/15697

This commit is contained in:
Daniel 2025-08-29 11:12:30 +08:00
parent 15f116f344
commit a154ead980
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -961,10 +961,8 @@ func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (c
pushBroadcastAttrTransactions(oldAttrs, toChangNode)
}
nodeTreeID := nodeTree.ID
for _, tree := range trees {
self := nodeTreeID == tree.ID
if !self {
if nodeTree.ID != tree.ID {
indexWriteTreeUpsertQueue(tree)
}
}
@ -1461,6 +1459,11 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
updatedNode.Tokens = []byte(strings.Join(newLines, "\n"))
}
removedNodes := getRemovedNodes(oldNode, updatedNode)
for _, n := range removedNodes {
syncDelete2AvBlock(n, tree, tx)
}
// 替换为新节点
oldNode.InsertAfter(updatedNode)
oldNode.Unlink()
@ -1520,6 +1523,30 @@ func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
return
}
func getRemovedNodes(oldNode, newNode *ast.Node) (ret []*ast.Node) {
oldNodes := map[string]*ast.Node{}
ast.Walk(oldNode, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}
oldNodes[n.ID] = n
return ast.WalkContinue
})
ast.Walk(newNode, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}
if _, ok := oldNodes[n.ID]; ok {
delete(oldNodes, n.ID)
}
return ast.WalkContinue
})
for _, n := range oldNodes {
ret = append(ret, n)
}
return
}
func upsertAvBlockRel(node *ast.Node) {
var affectedAvIDs []string
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {