Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-08-23 21:03:19 +08:00
commit eb578a3d9d
2 changed files with 25 additions and 66 deletions

View file

@ -2969,11 +2969,7 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
now := time.Now().UnixMilli() now := time.Now().UnixMilli()
for _, src := range srcs { for _, src := range srcs {
srcID := src["id"].(string) boundBlockID := ""
if !ast.IsNodeIDPattern(srcID) {
continue
}
srcItemID := ast.NewNodeID() srcItemID := ast.NewNodeID()
if nil != src["itemID"] { if nil != src["itemID"] {
srcItemID = src["itemID"].(string) srcItemID = src["itemID"].(string)
@ -2982,14 +2978,19 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
isDetached := src["isDetached"].(bool) isDetached := src["isDetached"].(bool)
var tree *parse.Tree var tree *parse.Tree
if !isDetached { if !isDetached {
boundBlockID = src["id"].(string)
if !ast.IsNodeIDPattern(boundBlockID) {
continue
}
var loadErr error var loadErr error
if nil != tx { if nil != tx {
tree, loadErr = tx.loadTree(srcID) tree, loadErr = tx.loadTree(boundBlockID)
} else { } else {
tree, loadErr = LoadTreeByBlockID(srcID) tree, loadErr = LoadTreeByBlockID(boundBlockID)
} }
if nil != loadErr { if nil != loadErr {
logging.LogErrorf("load tree [%s] failed: %s", srcID, loadErr) logging.LogErrorf("load tree [%s] failed: %s", boundBlockID, loadErr)
return loadErr return loadErr
} }
} }
@ -2998,7 +2999,7 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
if nil != src["content"] { if nil != src["content"] {
srcContent = src["content"].(string) srcContent = src["content"].(string)
} }
if avErr := addAttributeViewBlock(now, avID, dbBlockID, groupID, previousItemID, srcItemID, srcID, srcContent, isDetached, ignoreDefaultFill, tree, tx); nil != avErr { if avErr := addAttributeViewBlock(now, avID, dbBlockID, groupID, previousItemID, srcItemID, boundBlockID, srcContent, isDetached, ignoreDefaultFill, tree, tx); nil != avErr {
return avErr return avErr
} }
} }
@ -3039,7 +3040,7 @@ func addAttributeViewBlock(now int64, avID, dbBlockID, groupID, previousItemID,
// 检查是否重复添加相同的块 // 检查是否重复添加相同的块
blockValues := attrView.GetBlockKeyValues() blockValues := attrView.GetBlockKeyValues()
for _, blockValue := range blockValues.Values { for _, blockValue := range blockValues.Values {
if blockValue.Block.ID == addingBoundBlockID { if "" != addingBoundBlockID && blockValue.Block.ID == addingBoundBlockID {
if !isDetached { if !isDetached {
// 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要 // 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要
bindBlockAv0(tx, avID, node, tree) bindBlockAv0(tx, avID, node, tree)
@ -4264,18 +4265,18 @@ func replaceAttributeViewBlock(avID, oldBlockID, newBlockID string, isDetached b
return 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 avID := attrView.ID
var tree *parse.Tree var tree *parse.Tree
var node *ast.Node var node *ast.Node
if !isDetached { if !isDetached {
node, tree, _ = getNodeByBlockID(tx, newBlockID) node, tree, _ = getNodeByBlockID(tx, newNodeID)
} }
now := util.CurrentTimeMillis() now := util.CurrentTimeMillis()
// 检查是否已经存在绑定块,如果存在的话则重新绑定 // 检查是否已经存在绑定块,如果存在的话则重新绑定
for _, blockVal := range attrView.GetBlockKeyValues().Values { 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) bindBlockAv0(tx, avID, node, tree)
blockVal.IsDetached = false blockVal.IsDetached = false
icon, content := getNodeAvBlockText(node, "") icon, content := getNodeAvBlockText(node, "")
@ -4287,7 +4288,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
} }
} }
var changedAvIDs []string
for _, blockVal := range attrView.GetBlockKeyValues().Values { for _, blockVal := range attrView.GetBlockKeyValues().Values {
if blockVal.BlockID != oldBlockID { if blockVal.BlockID != oldBlockID {
continue continue
@ -4296,18 +4296,17 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
if av.KeyTypeBlock == blockVal.Type { if av.KeyTypeBlock == blockVal.Type {
blockVal.IsDetached = isDetached blockVal.IsDetached = isDetached
if !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) unbindBlockAv(tx, avID, blockVal.Block.ID)
} }
bindBlockAv(tx, avID, newBlockID) bindBlockAv(tx, avID, newNodeID)
blockVal.Block.ID = newBlockID blockVal.Block.ID = newNodeID
icon, content := getNodeAvBlockText(node, "") icon, content := getNodeAvBlockText(node, "")
content = util.UnescapeHTML(content) content = util.UnescapeHTML(content)
blockVal.Block.Icon, blockVal.Block.Content = icon, content blockVal.Block.Icon, blockVal.Block.Content = icon, content
avIDs := replaceRelationAvValues(avID, oldBlockID, newBlockID) refreshRelatedSrcAvs(avID)
changedAvIDs = append(changedAvIDs, avIDs...)
} else { } else {
blockVal.Block.ID = "" blockVal.Block.ID = ""
} }
@ -4315,11 +4314,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
} }
regenAttrViewGroups(attrView, "force") regenAttrViewGroups(attrView, "force")
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
for _, id := range changedAvIDs {
ReloadAttrView(id)
}
return return
} }
@ -5126,48 +5120,6 @@ func getAttrViewName(attrView *av.AttributeView) string {
return ret 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) { func updateBoundBlockAvsAttribute(avIDs []string) {
// 更新指定 avIDs 中绑定块的 avs 属性 // 更新指定 avIDs 中绑定块的 avs 属性

View file

@ -51,6 +51,13 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) {
} }
view.Sorts = tmpSorts view.Sorts = tmpSorts
// 字段删除以后需要删除设置的分组
if nil != view.Group {
if k, _ := attrView.GetKey(view.Group.Field); nil == k {
view.Group = nil
}
}
// 订正视图类型 // 订正视图类型
for i, v := range attrView.Views { for i, v := range attrView.Views {
if av.LayoutTypeGallery == v.LayoutType && nil == v.Gallery { if av.LayoutTypeGallery == v.LayoutType && nil == v.Gallery {