mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
⚡ Improve load tree performance
This commit is contained in:
parent
84b42d447a
commit
cb16111314
3 changed files with 26 additions and 33 deletions
|
|
@ -36,6 +36,23 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||||
|
ret = map[string]*parse.Tree{}
|
||||||
|
bts := treenode.GetBlockTrees(ids)
|
||||||
|
luteEngine := util.NewLute()
|
||||||
|
for id, bt := range bts {
|
||||||
|
if nil == ret[id] {
|
||||||
|
tree, err := LoadTree(bt.BoxID, bt.Path, luteEngine)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("load tree [%s] failed: %s", bt.Path, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret[id] = tree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
|
func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
|
||||||
filePath := filepath.Join(util.DataDir, boxID, p)
|
filePath := filepath.Join(util.DataDir, boxID, p)
|
||||||
data, err := filelock.ReadFile(filePath)
|
data, err := filelock.ReadFile(filePath)
|
||||||
|
|
|
||||||
|
|
@ -404,20 +404,9 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*SearchAt
|
||||||
}
|
}
|
||||||
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
||||||
|
|
||||||
trees := map[string]*parse.Tree{}
|
trees := filesys.LoadTrees(blockIDs)
|
||||||
for _, blockID := range blockIDs {
|
for _, blockID := range blockIDs {
|
||||||
bt := treenode.GetBlockTree(blockID)
|
tree := trees[blockID]
|
||||||
if nil == bt {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tree := trees[bt.RootID]
|
|
||||||
if nil == tree {
|
|
||||||
tree, _ = LoadTreeByBlockID(blockID)
|
|
||||||
if nil != tree {
|
|
||||||
trees[bt.RootID] = tree
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -1428,10 +1417,10 @@ func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMirrorBlocksNodes(avID string) (trees []*parse.Tree, nodes []*ast.Node) {
|
func getMirrorBlocksNodes(avID string) (trees []*parse.Tree, nodes []*ast.Node) {
|
||||||
mirrorBlocks := treenode.GetMirrorAttrViewBlockIDs(avID)
|
mirrorBlockIDs := treenode.GetMirrorAttrViewBlockIDs(avID)
|
||||||
mirrorBlockTree := map[string]*parse.Tree{}
|
mirrorBlockTree := map[string]*parse.Tree{}
|
||||||
treeCache := map[string]*parse.Tree{}
|
treeCache := map[string]*parse.Tree{}
|
||||||
for _, mirrorBlock := range mirrorBlocks {
|
for _, mirrorBlock := range mirrorBlockIDs {
|
||||||
bt := treenode.GetBlockTree(mirrorBlock)
|
bt := treenode.GetBlockTree(mirrorBlock)
|
||||||
if nil == bt {
|
if nil == bt {
|
||||||
logging.LogErrorf("get block tree by block ID [%s] failed", mirrorBlock)
|
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 {
|
for _, mirrorBlockID := range mirrorBlockIDs {
|
||||||
tree := mirrorBlockTree[mirrorBlock]
|
tree := mirrorBlockTree[mirrorBlockID]
|
||||||
node := treenode.GetNodeInTree(tree, mirrorBlock)
|
node := treenode.GetNodeInTree(tree, mirrorBlockID)
|
||||||
if nil == node {
|
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
|
continue
|
||||||
}
|
}
|
||||||
nodes = append(nodes, node)
|
nodes = append(nodes, node)
|
||||||
|
|
|
||||||
|
|
@ -292,20 +292,7 @@ func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
|
|
||||||
ret = map[string]map[string]string{}
|
ret = map[string]map[string]string{}
|
||||||
trees := map[string]*parse.Tree{}
|
trees := filesys.LoadTrees(ids)
|
||||||
bts := treenode.GetBlockTrees(ids)
|
|
||||||
luteEngine := util.NewLute()
|
|
||||||
for id, bt := range bts {
|
|
||||||
if nil == trees[id] {
|
|
||||||
tree, err := filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
|
||||||
if nil != err {
|
|
||||||
logging.LogErrorf("load tree [%s] failed: %s", bt.Path, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
trees[id] = tree
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
tree := trees[id]
|
tree := trees[id]
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue