Improve document tree expansion and database loading performance https://github.com/siyuan-note/siyuan/issues/12428

This commit is contained in:
Daniel 2024-09-09 23:45:04 +08:00
parent d2aec48657
commit 42c9a1210a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 31 additions and 14 deletions

View file

@ -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