mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 07:48:49 +01:00
⚡ Improve document tree expansion and database loading performance https://github.com/siyuan-note/siyuan/issues/12428
This commit is contained in:
parent
d2aec48657
commit
42c9a1210a
2 changed files with 31 additions and 14 deletions
|
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
util2 "github.com/88250/lute/util"
|
||||
"github.com/facette/natsort"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/riff"
|
||||
|
|
@ -117,18 +118,28 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
|||
|
||||
filePath := filepath.Join(util.DataDir, box.ID, p)
|
||||
|
||||
data, err := filelock.ReadFile(filePath)
|
||||
if util.IsCorruptedSYData(data) {
|
||||
box.moveCorruptedData(filePath)
|
||||
return nil
|
||||
}
|
||||
filelock.Lock(filePath)
|
||||
defer filelock.Unlock(filePath)
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
logging.LogErrorf("read file [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("open file [%s] failed: %s", p, err)
|
||||
return nil
|
||||
}
|
||||
ret = filesys.ReadDocIAL(data)
|
||||
defer file.Close()
|
||||
|
||||
iter := jsoniter.Parse(jsoniter.ConfigCompatibleWithStandardLibrary, file, 512)
|
||||
for field := iter.ReadObject(); field != ""; field = iter.ReadObject() {
|
||||
if field == "Properties" {
|
||||
iter.ReadVal(&ret)
|
||||
break
|
||||
} else {
|
||||
iter.Skip()
|
||||
}
|
||||
}
|
||||
|
||||
if 1 > len(ret) {
|
||||
logging.LogWarnf("tree [%s] is corrupted", filePath)
|
||||
logging.LogWarnf("properties not found in file [%s]", p)
|
||||
box.moveCorruptedData(filePath)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -241,6 +252,12 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
//pprof.StartCPUProfile(cpuProfile)
|
||||
//defer pprof.StopCPUProfile()
|
||||
|
||||
start1 := time.Now()
|
||||
defer func() {
|
||||
elapsed := time.Now().Sub(start1).Milliseconds()
|
||||
logging.LogInfof("list doc tree elapsed [%dms]", elapsed)
|
||||
}()
|
||||
|
||||
ret = []*File{}
|
||||
|
||||
var deck *riff.Deck
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue