From e7d1210ec9e285a6806eecbad3ca0805c7cb2069 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 28 Mar 2024 21:27:31 +0800 Subject: [PATCH] :art: Improve av https://ld246.com/article/1711613722864 --- kernel/model/attribute_view.go | 43 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index ff356fb4c..70c4a481a 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -901,7 +901,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s continue } - if treenode.GetBlockTree(blockID) == nil { + if nil == treenode.GetBlockTree(blockID) { notFound = append(notFound, blockID) } } @@ -1985,6 +1985,10 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string, blockValues := attrView.GetBlockKeyValues() for _, blockValue := range blockValues.Values { if blockValue.Block.ID == addingBlockID { + if !isDetached { + // 重复绑定一下,比如剪切数据库块的场景需要 + bindBlockAv0(tx, avID, blockID, node, tree) + } return } } @@ -2074,31 +2078,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string, } if !isDetached { - attrs := parse.IAL2Map(node.KramdownIAL) - - if "" == attrs[av.NodeAttrNameAvs] { - attrs[av.NodeAttrNameAvs] = avID - } else { - avIDs := strings.Split(attrs[av.NodeAttrNameAvs], ",") - avIDs = append(avIDs, avID) - avIDs = gulu.Str.RemoveDuplicatedElem(avIDs) - attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",") - } - - avNames := getAvNames(attrs[av.NodeAttrNameAvs]) - if "" != avNames { - attrs[av.NodeAttrViewNames] = avNames - } - - if nil != tx { - if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err { - return - } - } else { - if err = setNodeAttrs(node, tree, attrs); nil != err { - return - } - } + bindBlockAv0(tx, avID, blockID, node, tree) } for _, view := range attrView.Views { @@ -3036,6 +3016,11 @@ func bindBlockAv(tx *Transaction, avID, blockID string) { return } + bindBlockAv0(tx, avID, blockID, node, tree) + return +} + +func bindBlockAv0(tx *Transaction, avID, blockID string, node *ast.Node, tree *parse.Tree) { attrs := parse.IAL2Map(node.KramdownIAL) if "" == attrs[av.NodeAttrNameAvs] { attrs[av.NodeAttrNameAvs] = avID @@ -3046,6 +3031,12 @@ func bindBlockAv(tx *Transaction, avID, blockID string) { attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",") } + avNames := getAvNames(attrs[av.NodeAttrNameAvs]) + if "" != avNames { + attrs[av.NodeAttrViewNames] = avNames + } + + var err error if nil != tx { err = setNodeAttrsWithTx(tx, node, tree, attrs) } else {