From 9eec8510b720c5f440eb37806fb8c0e01c6ffb70 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 18:44:26 +0800 Subject: [PATCH 1/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15528 --- kernel/model/attribute_view.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index fc93843c6..3087f4335 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -2969,11 +2969,7 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, now := time.Now().UnixMilli() for _, src := range srcs { - srcID := src["id"].(string) - if !ast.IsNodeIDPattern(srcID) { - continue - } - + boundBlockID := "" srcItemID := ast.NewNodeID() if nil != src["itemID"] { srcItemID = src["itemID"].(string) @@ -2982,14 +2978,19 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, isDetached := src["isDetached"].(bool) var tree *parse.Tree if !isDetached { + boundBlockID = src["id"].(string) + if !ast.IsNodeIDPattern(boundBlockID) { + continue + } + var loadErr error if nil != tx { - tree, loadErr = tx.loadTree(srcID) + tree, loadErr = tx.loadTree(boundBlockID) } else { - tree, loadErr = LoadTreeByBlockID(srcID) + tree, loadErr = LoadTreeByBlockID(boundBlockID) } if nil != loadErr { - logging.LogErrorf("load tree [%s] failed: %s", srcID, loadErr) + logging.LogErrorf("load tree [%s] failed: %s", boundBlockID, loadErr) return loadErr } } @@ -2998,7 +2999,7 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, if nil != src["content"] { 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 } } From 91a9b27789ebe4a205f0a513e61651bf7d9b14ab Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 18:48:54 +0800 Subject: [PATCH 2/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15528 --- kernel/model/attribute_view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 3087f4335..963cc0ad5 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -3040,7 +3040,7 @@ func addAttributeViewBlock(now int64, avID, dbBlockID, groupID, previousItemID, // 检查是否重复添加相同的块 blockValues := attrView.GetBlockKeyValues() for _, blockValue := range blockValues.Values { - if blockValue.Block.ID == addingBoundBlockID { + if "" != addingBoundBlockID && blockValue.Block.ID == addingBoundBlockID { if !isDetached { // 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要 bindBlockAv0(tx, avID, node, tree) From fb9f0f9a353ba5de87d5be95f27120013bbc8fed Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 19:42:39 +0800 Subject: [PATCH 3/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15659 --- kernel/model/attribute_view_fix.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/model/attribute_view_fix.go b/kernel/model/attribute_view_fix.go index 157649d5d..fa0509859 100644 --- a/kernel/model/attribute_view_fix.go +++ b/kernel/model/attribute_view_fix.go @@ -51,6 +51,13 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) { } 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 { if av.LayoutTypeGallery == v.LayoutType && nil == v.Gallery { From e7eb62e660f1f0d01146b1401447bd05a9510c5b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 19:53:38 +0800 Subject: [PATCH 4/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15665 --- kernel/model/attribute_view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 963cc0ad5..583baf071 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -4307,7 +4307,7 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock content = util.UnescapeHTML(content) blockVal.Block.Icon, blockVal.Block.Content = icon, content - avIDs := replaceRelationAvValues(avID, oldBlockID, newBlockID) + avIDs := replaceRelationAvValues(avID, blockVal.Block.ID, newBlockID) changedAvIDs = append(changedAvIDs, avIDs...) } else { blockVal.Block.ID = "" From 77c1aa49b32b3a3a54a68fee3f7632703c6bac0e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 19:57:40 +0800 Subject: [PATCH 5/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15665 --- kernel/model/attribute_view.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 583baf071..6dbce775d 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -4302,12 +4302,11 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock } bindBlockAv(tx, avID, newBlockID) - blockVal.Block.ID = newBlockID 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...) } else { blockVal.Block.ID = "" From a5ca8efcae9ce298694dc099f40f8c4fcbe51e30 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Aug 2025 20:09:16 +0800 Subject: [PATCH 6/6] :art: Improve av https://github.com/siyuan-note/siyuan/issues/15665 --- kernel/model/attribute_view.go | 64 +++++----------------------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 6dbce775d..af0479068 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -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 属性