This commit is contained in:
Daniel 2024-09-26 09:00:35 +08:00
parent 2deb986c87
commit fb914ab674
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 21 additions and 12 deletions

View file

@ -1675,7 +1675,7 @@ func (tx *Transaction) doSetAttrViewViewIcon(operation *Operation) (ret *TxErr)
}
func (tx *Transaction) doSetAttrViewName(operation *Operation) (ret *TxErr) {
err := setAttributeViewName(operation)
err := tx.setAttributeViewName(operation)
if err != nil {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
}
@ -1684,7 +1684,7 @@ func (tx *Transaction) doSetAttrViewName(operation *Operation) (ret *TxErr) {
const attrAvNameTpl = `<span data-av-id="${avID}" data-popover-url="/api/av/getMirrorDatabaseBlocks" class="popover__block">${avName}</span>`
func setAttributeViewName(operation *Operation) (err error) {
func (tx *Transaction) setAttributeViewName(operation *Operation) (err error) {
avID := operation.ID
attrView, err := av.ParseAttributeView(avID)
if err != nil {
@ -1694,7 +1694,7 @@ func setAttributeViewName(operation *Operation) (err error) {
attrView.Name = strings.TrimSpace(operation.Data.(string))
err = av.SaveAttributeView(attrView)
_, nodes := getAttrViewBoundNodes(attrView)
_, nodes := tx.getAttrViewBoundNodes(attrView)
for _, node := range nodes {
avNames := getAvNames(node.IALAttr(av.NodeAttrNameAvs))
oldAttrs := parse.IAL2Map(node.KramdownIAL)
@ -1731,7 +1731,7 @@ func getAvNames(avIDs string) (ret string) {
return
}
func getAttrViewBoundNodes(attrView *av.AttributeView) (trees []*parse.Tree, nodes []*ast.Node) {
func (tx *Transaction) getAttrViewBoundNodes(attrView *av.AttributeView) (trees []*parse.Tree, nodes []*ast.Node) {
blockKeyValues := attrView.GetBlockKeyValues()
treeCache := map[string]*parse.Tree{}
for _, blockKeyValue := range blockKeyValues.Values {
@ -1742,7 +1742,11 @@ func getAttrViewBoundNodes(attrView *av.AttributeView) (trees []*parse.Tree, nod
var tree *parse.Tree
tree = treeCache[blockKeyValue.BlockID]
if nil == tree {
tree, _ = LoadTreeByBlockID(blockKeyValue.BlockID)
if nil == tx {
tree, _ = LoadTreeByBlockID(blockKeyValue.BlockID)
} else {
tree, _ = tx.loadTree(blockKeyValue.BlockID)
}
}
if nil == tree {
continue

View file

@ -1704,7 +1704,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
continue
}
syncDelete2AvBlock(removeTree.Root)
syncDelete2AvBlock(removeTree.Root, removeTree, nil)
}
if existChildren {

View file

@ -819,14 +819,14 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
}
if needSyncDel2AvBlock {
syncDelete2AvBlock(node)
syncDelete2AvBlock(node, tree, tx)
}
return
}
func syncDelete2AvBlock(node *ast.Node) {
func syncDelete2AvBlock(node *ast.Node, nodeTree *parse.Tree, tx *Transaction) {
changedAvIDs := syncDelete2AttributeView(node)
avIDs := syncDelete2Block(node)
avIDs := tx.syncDelete2Block(node, nodeTree)
changedAvIDs = append(changedAvIDs, avIDs...)
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
@ -835,7 +835,7 @@ func syncDelete2AvBlock(node *ast.Node) {
}
}
func syncDelete2Block(node *ast.Node) (changedAvIDs []string) {
func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (changedAvIDs []string) {
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeAttributeView != n.Type {
return ast.WalkContinue
@ -857,7 +857,7 @@ func syncDelete2Block(node *ast.Node) (changedAvIDs []string) {
return ast.WalkContinue
}
trees, nodes := getAttrViewBoundNodes(attrView)
trees, nodes := tx.getAttrViewBoundNodes(attrView)
for _, toChangNode := range nodes {
avs := toChangNode.IALAttr(av.NodeAttrNameAvs)
if "" != avs {
@ -874,8 +874,13 @@ func syncDelete2Block(node *ast.Node) (changedAvIDs []string) {
toChangNode.SetIALAttr(av.NodeAttrViewNames, avNames)
pushBroadcastAttrTransactions(oldAttrs, toChangNode)
}
nodeTreeID := nodeTree.ID
for _, tree := range trees {
indexWriteTreeUpsertQueue(tree)
self := nodeTreeID == tree.ID
if !self {
indexWriteTreeUpsertQueue(tree)
}
}
return ast.WalkContinue
})