Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Remove rows in database bound to child blocks when deleting parent block https://github.com/siyuan-note/siyuan/issues/10923

Daniel20ecabc6c399
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 39f4802114..0d258f42a3 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -811,35 +811,48 @@ func removeAvBlockRel(node *ast.Node) {
}
func syncDelete2AttributeView(node *ast.Node) {
- avs := node.IALAttr(av.NodeAttrNameAvs)
- if "" == avs {
- return
- }
-
- avIDs := strings.Split(avs, ",")
- for _, avID := range avIDs {
- attrView, parseErr := av.ParseAttributeView(avID)
- if nil != parseErr {
- continue
+ changedAvIDs := hashset.New()
+ ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
+ if !entering || !n.IsBlock() {
+ return ast.WalkContinue
}
- changedAv := false
- blockValues := attrView.GetBlockKeyValues()
- if nil == blockValues {
- continue
+ avs := n.IALAttr(av.NodeAttrNameAvs)
+ if "" == avs {
+ return ast.WalkContinue
}
- for i, blockValue := range blockValues.Values {
- if blockValue.Block.ID == node.ID {
- blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
- changedAv = true
- break
+ avIDs := strings.Split(avs, ",")
+ for _, avID := range avIDs {
+ attrView, parseErr := av.ParseAttributeView(avID)
+ if nil != parseErr {
+ continue
+ }
+
+ changedAv := false
+ blockValues := attrView.GetBlockKeyValues()
+ if nil == blockValues {
+ continue
+ }
+
+ for i, blockValue := range blockValues.Values {
+ if blockValue.Block.ID == n.ID {
+ blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
+ changedAv = true
+ break
+ }
+ }
+
+ if changedAv {
+ av.SaveAttributeView(attrView)
+ changedAvIDs.Add(avID)
}
}
- if changedAv {
- av.SaveAttributeView(attrView)
- util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
- }
+ return ast.WalkContinue
+ })
+
+ for _, avID := range changedAvIDs.Values() {
+ util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
}
}