This commit is contained in:
Daniel 2025-08-23 20:09:16 +08:00
parent 77c1aa49b3
commit a5ca8efcae
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -4265,18 +4265,18 @@ func replaceAttributeViewBlock(avID, oldBlockID, newBlockID string, isDetached b
return
}
func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlockID string, isDetached bool, tx *Transaction) (err error) {
func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newNodeID string, isDetached bool, tx *Transaction) (err error) {
avID := attrView.ID
var tree *parse.Tree
var node *ast.Node
if !isDetached {
node, tree, _ = getNodeByBlockID(tx, newBlockID)
node, tree, _ = getNodeByBlockID(tx, newNodeID)
}
now := util.CurrentTimeMillis()
// 检查是否已经存在绑定块,如果存在的话则重新绑定
for _, blockVal := range attrView.GetBlockKeyValues().Values {
if !isDetached && blockVal.Block.ID == newBlockID && nil != node && nil != tree {
if !isDetached && blockVal.Block.ID == newNodeID && nil != node && nil != tree {
bindBlockAv0(tx, avID, node, tree)
blockVal.IsDetached = false
icon, content := getNodeAvBlockText(node, "")
@ -4288,7 +4288,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
}
}
var changedAvIDs []string
for _, blockVal := range attrView.GetBlockKeyValues().Values {
if blockVal.BlockID != oldBlockID {
continue
@ -4297,17 +4296,17 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
if av.KeyTypeBlock == blockVal.Type {
blockVal.IsDetached = isDetached
if !isDetached {
if "" != blockVal.Block.ID && blockVal.Block.ID != newBlockID {
if "" != blockVal.Block.ID && blockVal.Block.ID != newNodeID {
unbindBlockAv(tx, avID, blockVal.Block.ID)
}
bindBlockAv(tx, avID, newBlockID)
bindBlockAv(tx, avID, newNodeID)
blockVal.Block.ID = newNodeID
icon, content := getNodeAvBlockText(node, "")
content = util.UnescapeHTML(content)
blockVal.Block.Icon, blockVal.Block.Content = icon, content
avIDs := replaceRelationAvValues(avID, blockVal.Block.ID, newBlockID)
blockVal.Block.ID = newBlockID
changedAvIDs = append(changedAvIDs, avIDs...)
refreshRelatedSrcAvs(avID)
} else {
blockVal.Block.ID = ""
}
@ -4315,11 +4314,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
}
regenAttrViewGroups(attrView, "force")
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
for _, id := range changedAvIDs {
ReloadAttrView(id)
}
return
}
@ -5126,48 +5120,6 @@ func getAttrViewName(attrView *av.AttributeView) string {
return ret
}
func replaceRelationAvValues(avID, previousID, nextID string) (changedSrcAvID []string) {
// The database relation fields follow the change after the primary key field is changed https://github.com/siyuan-note/siyuan/issues/11117
srcAvIDs := av.GetSrcAvIDs(avID)
for _, srcAvID := range srcAvIDs {
srcAv, parseErr := av.ParseAttributeView(srcAvID)
changed := false
if nil != parseErr {
continue
}
for _, srcKeyValues := range srcAv.KeyValues {
if av.KeyTypeRelation != srcKeyValues.Key.Type {
continue
}
if nil == srcKeyValues.Key.Relation || avID != srcKeyValues.Key.Relation.AvID {
continue
}
for _, srcValue := range srcKeyValues.Values {
if nil == srcValue.Relation {
continue
}
srcAvChanged := false
srcValue.Relation.BlockIDs, srcAvChanged = util.ReplaceStr(srcValue.Relation.BlockIDs, previousID, nextID)
if srcAvChanged {
changed = true
}
}
}
if changed {
regenAttrViewGroups(srcAv, "force")
av.SaveAttributeView(srcAv)
changedSrcAvID = append(changedSrcAvID, srcAvID)
}
}
return
}
func updateBoundBlockAvsAttribute(avIDs []string) {
// 更新指定 avIDs 中绑定块的 avs 属性