Improve load tree performance

This commit is contained in:
Daniel 2024-06-21 23:37:47 +08:00
parent 84b42d447a
commit cb16111314
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 26 additions and 33 deletions

View file

@ -404,20 +404,9 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*SearchAt
}
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
trees := map[string]*parse.Tree{}
trees := filesys.LoadTrees(blockIDs)
for _, blockID := range blockIDs {
bt := treenode.GetBlockTree(blockID)
if nil == bt {
continue
}
tree := trees[bt.RootID]
if nil == tree {
tree, _ = LoadTreeByBlockID(blockID)
if nil != tree {
trees[bt.RootID] = tree
}
}
tree := trees[blockID]
if nil == tree {
continue
}
@ -1428,10 +1417,10 @@ func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
}
func getMirrorBlocksNodes(avID string) (trees []*parse.Tree, nodes []*ast.Node) {
mirrorBlocks := treenode.GetMirrorAttrViewBlockIDs(avID)
mirrorBlockIDs := treenode.GetMirrorAttrViewBlockIDs(avID)
mirrorBlockTree := map[string]*parse.Tree{}
treeCache := map[string]*parse.Tree{}
for _, mirrorBlock := range mirrorBlocks {
for _, mirrorBlock := range mirrorBlockIDs {
bt := treenode.GetBlockTree(mirrorBlock)
if nil == bt {
logging.LogErrorf("get block tree by block ID [%s] failed", mirrorBlock)
@ -1450,11 +1439,11 @@ func getMirrorBlocksNodes(avID string) (trees []*parse.Tree, nodes []*ast.Node)
}
}
for _, mirrorBlock := range mirrorBlocks {
tree := mirrorBlockTree[mirrorBlock]
node := treenode.GetNodeInTree(tree, mirrorBlock)
for _, mirrorBlockID := range mirrorBlockIDs {
tree := mirrorBlockTree[mirrorBlockID]
node := treenode.GetNodeInTree(tree, mirrorBlockID)
if nil == node {
logging.LogErrorf("get node in tree by block ID [%s] failed", mirrorBlock)
logging.LogErrorf("get node in tree by block ID [%s] failed", mirrorBlockID)
continue
}
nodes = append(nodes, node)