mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Clean code https://github.com/siyuan-note/siyuan/pull/12723
This commit is contained in:
parent
7afea33d36
commit
dbe83baef5
2 changed files with 10 additions and 12 deletions
|
|
@ -21,6 +21,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/88250/lute/render"
|
"github.com/88250/lute/render"
|
||||||
|
|
@ -30,10 +35,6 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||||
|
|
@ -80,10 +81,10 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) ([]*parse.Tree, []error) {
|
func BatchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) ([]*parse.Tree, []error) {
|
||||||
var wg sync.WaitGroup
|
|
||||||
results := make([]*parse.Tree, len(paths))
|
results := make([]*parse.Tree, len(paths))
|
||||||
errors := make([]error, len(paths))
|
errs := make([]error, len(paths))
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
for i := range paths {
|
for i := range paths {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
|
|
@ -91,17 +92,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
|
results[i] = tree
|
||||||
errors[i] = err
|
errs[i] = err
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
return results, errors
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -30,6 +29,7 @@ import (
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue