Skip to content

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

:art: Improve database unbind block https://github.com/siyuan-note/siyuan/issues/11013

Daniel97f8d6c013a8
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index dc3cd05793..161602dc31 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1301,18 +1301,20 @@ func unbindAttributeViewBlock(operation *Operation, tx *Transaction) (err error)
return
}
- keyValues := attrView.GetBlockKeyValues()
- for _, value := range keyValues.Values {
- if value.BlockID != operation.ID {
- continue
- }
+ for _, keyValues := range attrView.KeyValues {
+ for _, value := range keyValues.Values {
+ if value.BlockID != operation.ID {
+ continue
+ }
- unbindBlockAv(tx, operation.AvID, value.BlockID)
- value.BlockID = operation.NextID
- if nil != value.Block {
- value.Block.ID = operation.NextID
+ if av.KeyTypeBlock == value.Type {
+ unbindBlockAv(tx, operation.AvID, value.BlockID)
+ }
+ value.BlockID = operation.NextID
+ if nil != value.Block {
+ value.Block.ID = operation.NextID
+ }
}
- break
}
replacedRowID := false
@@ -2956,25 +2958,27 @@ func replaceAttributeViewBlock(operation *Operation, tx *Transaction) (err error
for _, keyValues := range attrView.KeyValues {
for _, value := range keyValues.Values {
- if value.BlockID == operation.PreviousID {
- if value.BlockID != operation.NextID {
- // 换绑
- unbindBlockAv(tx, operation.AvID, value.BlockID)
- }
-
- value.BlockID = operation.NextID
- if nil != value.Block {
- value.Block.ID = operation.NextID
- value.IsDetached = operation.IsDetached
- if !operation.IsDetached {
- value.Block.Content = getNodeRefText(node)
- }
- }
+ if value.BlockID != operation.PreviousID {
+ continue
+ }
+ if av.KeyTypeBlock == value.Type && value.BlockID != operation.NextID {
+ // 换绑
+ unbindBlockAv(tx, operation.AvID, value.BlockID)
+ }
+
+ value.BlockID = operation.NextID
+ if av.KeyTypeBlock == value.Type && nil != value.Block {
+ value.Block.ID = operation.NextID
+ value.IsDetached = operation.IsDetached
if !operation.IsDetached {
- bindBlockAv(tx, operation.AvID, operation.NextID)
+ value.Block.Content = getNodeRefText(node)
}
}
+
+ if av.KeyTypeBlock == value.Type && !operation.IsDetached {
+ bindBlockAv(tx, operation.AvID, operation.NextID)
+ }
}
}