⚡ Improve load tree performance
This commit is contained in:
parent
cb16111314
commit
1452e7cf3f
3 changed files with 19 additions and 22 deletions
|
@ -37,18 +37,20 @@ import (
|
|||
)
|
||||
|
||||
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||
ret = map[string]*parse.Tree{}
|
||||
ret, tmpCache := map[string]*parse.Tree{}, 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)
|
||||
tree := tmpCache[bt.RootID]
|
||||
if nil == tree {
|
||||
tree, _ = LoadTree(bt.BoxID, bt.Path, luteEngine)
|
||||
if nil == tree {
|
||||
logging.LogWarnf("load tree [%s] failed: %s", id, bt.Path)
|
||||
continue
|
||||
}
|
||||
ret[id] = tree
|
||||
tmpCache[bt.RootID] = tree
|
||||
}
|
||||
ret[id] = tree
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -557,11 +557,16 @@ func (box *Box) UpdateHistoryGenerated() {
|
|||
|
||||
func getBoxesByPaths(paths []string) (ret map[string]*Box) {
|
||||
ret = map[string]*Box{}
|
||||
var ids []string
|
||||
for _, p := range paths {
|
||||
id := strings.TrimSuffix(path.Base(p), ".sy")
|
||||
bt := treenode.GetBlockTree(id)
|
||||
ids = append(ids, strings.TrimSuffix(path.Base(p), ".sy"))
|
||||
}
|
||||
|
||||
bts := treenode.GetBlockTrees(ids)
|
||||
for _, id := range ids {
|
||||
bt := bts[id]
|
||||
if nil != bt {
|
||||
ret[p] = Conf.Box(bt.BoxID)
|
||||
ret[bt.Path] = Conf.Box(bt.BoxID)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -465,21 +465,11 @@ func contentStat(content string, luteEngine *lute.Lute) (ret *util.BlockStatResu
|
|||
|
||||
func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
|
||||
ret = &util.BlockStatResult{}
|
||||
trees := map[string]*parse.Tree{} // 缓存
|
||||
luteEngine := util.NewLute()
|
||||
trees := filesys.LoadTrees(ids)
|
||||
for _, id := range ids {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
continue
|
||||
}
|
||||
|
||||
tree := trees[bt.RootID]
|
||||
tree := trees[id]
|
||||
if nil == tree {
|
||||
tree, _ = filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
||||
if nil == tree {
|
||||
continue
|
||||
}
|
||||
trees[bt.RootID] = tree
|
||||
continue
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
|
|
Loading…
Add table
Reference in a new issue