mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🐛 Add a kernel API /api/block/getDocsInfo https://github.com/siyuan-note/siyuan/pull/12723 https://github.com/siyuan-note/siyuan/issues/12740
This commit is contained in:
parent
97eb7de2c3
commit
7028759499
1 changed files with 13 additions and 12 deletions
|
|
@ -43,18 +43,19 @@ func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||||
luteEngine := util.NewLute()
|
luteEngine := util.NewLute()
|
||||||
var boxIDs []string
|
var boxIDs []string
|
||||||
var paths []string
|
var paths []string
|
||||||
seen := make(map[string]bool)
|
blockIDs := map[string]string{}
|
||||||
|
seen := map[string]bool{}
|
||||||
for _, bt := range bts {
|
for _, bt := range bts {
|
||||||
key := bt.BoxID + bt.Path
|
key := bt.BoxID + bt.Path
|
||||||
if !seen[key] {
|
if !seen[key] {
|
||||||
seen[key] = true
|
seen[key] = true
|
||||||
boxIDs = append(boxIDs, bt.BoxID)
|
boxIDs = append(boxIDs, bt.BoxID)
|
||||||
paths = append(paths, bt.Path)
|
paths = append(paths, bt.Path)
|
||||||
|
blockIDs[bt.RootID] = bt.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trees, errs := BatchLoadTrees(boxIDs, paths, luteEngine)
|
trees, errs := batchLoadTrees(boxIDs, paths, luteEngine)
|
||||||
|
|
||||||
for i := range trees {
|
for i := range trees {
|
||||||
tree := trees[i]
|
tree := trees[i]
|
||||||
err := errs[i]
|
err := errs[i]
|
||||||
|
|
@ -63,7 +64,8 @@ func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ret[tree.ID] = tree
|
id := blockIDs[tree.Root.ID]
|
||||||
|
ret[id] = tree
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -80,11 +82,9 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) ([]*parse.Tree, []error) {
|
func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse.Tree, errs []error) {
|
||||||
results := make([]*parse.Tree, len(paths))
|
|
||||||
errs := make([]error, len(paths))
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
lock := sync.Mutex{}
|
||||||
for i := range paths {
|
for i := range paths {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
|
|
@ -93,13 +93,14 @@ func BatchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) ([]*parse.Tre
|
||||||
boxID := boxIDs[i]
|
boxID := boxIDs[i]
|
||||||
path := paths[i]
|
path := paths[i]
|
||||||
tree, err := LoadTree(boxID, path, luteEngine)
|
tree, err := LoadTree(boxID, path, luteEngine)
|
||||||
results[i] = tree
|
lock.Lock()
|
||||||
errs[i] = err
|
ret = append(ret, tree)
|
||||||
|
errs = append(errs, err)
|
||||||
|
lock.Unlock()
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
return
|
||||||
return results, errs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
|
func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue