diff --git a/kernel/cache/ial.go b/kernel/cache/ial.go index 92de587fb..2cb72c03c 100644 --- a/kernel/cache/ial.go +++ b/kernel/cache/ial.go @@ -24,13 +24,13 @@ import ( ) var docIALCache, _ = ristretto.NewCache(&ristretto.Config{ - NumCounters: 102400, - MaxCost: 10240, + NumCounters: 1024 * 100, + MaxCost: 1024 * 1024 * 200, BufferItems: 64, }) func PutDocIAL(p string, ial map[string]string) { - docIALCache.Set(p, ial, 1) + docIALCache.Set(p, ial, 128) } func GetDocIAL(p string) (ret map[string]string) { @@ -55,13 +55,13 @@ func ClearDocsIAL() { } var blockIALCache, _ = ristretto.NewCache(&ristretto.Config{ - NumCounters: 102400, - MaxCost: 10240, + NumCounters: 1024 * 1000, + MaxCost: 1024 * 1024 * 200, BufferItems: 64, }) func PutBlockIAL(id string, ial map[string]string) { - blockIALCache.Set(id, ial, 1) + blockIALCache.Set(id, ial, 128) } func GetBlockIAL(id string) (ret map[string]string) { diff --git a/kernel/model/file.go b/kernel/model/file.go index 8e3de81c0..f2e720721 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -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