mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 00:20:12 +01:00
⚡ Improve load tree performance
This commit is contained in:
parent
56d7a3e2b8
commit
0c0cc55820
2 changed files with 35 additions and 40 deletions
|
|
@ -150,9 +150,9 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
||||||
parentAbsPath += ".sy"
|
parentAbsPath += ".sy"
|
||||||
parentPath := parentAbsPath
|
parentPath := parentAbsPath
|
||||||
parentAbsPath = filepath.Join(util.DataDir, boxID, parentAbsPath)
|
parentAbsPath = filepath.Join(util.DataDir, boxID, parentAbsPath)
|
||||||
parentData, readErr := filelock.ReadFile(parentAbsPath)
|
|
||||||
if nil != readErr {
|
parentDocIAL := DocIAL(parentAbsPath)
|
||||||
if os.IsNotExist(readErr) {
|
if 1 > len(parentDocIAL) {
|
||||||
// 子文档缺失父文档时自动补全 https://github.com/siyuan-note/siyuan/issues/7376
|
// 子文档缺失父文档时自动补全 https://github.com/siyuan-note/siyuan/issues/7376
|
||||||
parentTree := treenode.NewTree(boxID, parentPath, hPathBuilder.String()+"Untitled", "Untitled")
|
parentTree := treenode.NewTree(boxID, parentPath, hPathBuilder.String()+"Untitled", "Untitled")
|
||||||
if _, writeErr := WriteTree(parentTree); nil != writeErr {
|
if _, writeErr := WriteTree(parentTree); nil != writeErr {
|
||||||
|
|
@ -161,18 +161,11 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
||||||
logging.LogInfof("rebuilt parent tree [%s]", parentAbsPath)
|
logging.LogInfof("rebuilt parent tree [%s]", parentAbsPath)
|
||||||
treenode.UpsertBlockTree(parentTree)
|
treenode.UpsertBlockTree(parentTree)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr)
|
|
||||||
}
|
|
||||||
hPathBuilder.WriteString("Untitled/")
|
hPathBuilder.WriteString("Untitled/")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ial := ReadDocIAL(parentData)
|
title := parentDocIAL["title"]
|
||||||
if 1 > len(ial) {
|
|
||||||
logging.LogWarnf("tree [%s] is corrupted", filepath.Join(boxID, p))
|
|
||||||
}
|
|
||||||
title := ial["title"]
|
|
||||||
if "" == title {
|
if "" == title {
|
||||||
title = "Untitled"
|
title = "Untitled"
|
||||||
}
|
}
|
||||||
|
|
@ -185,6 +178,29 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DocIAL(absPath string) (ret map[string]string) {
|
||||||
|
filelock.Lock(absPath)
|
||||||
|
file, err := os.Open(absPath)
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("open file [%s] failed: %s", absPath, err)
|
||||||
|
filelock.Unlock(absPath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
filelock.Unlock(absPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func WriteTree(tree *parse.Tree) (size uint64, err error) {
|
func WriteTree(tree *parse.Tree) (size uint64, err error) {
|
||||||
data, filePath, err := prepareWriteTree(tree)
|
data, filePath, err := prepareWriteTree(tree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import (
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
util2 "github.com/88250/lute/util"
|
util2 "github.com/88250/lute/util"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/riff"
|
"github.com/siyuan-note/riff"
|
||||||
|
|
@ -116,29 +115,9 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := filepath.Join(util.DataDir, box.ID, p)
|
filePath := filepath.Join(util.DataDir, box.ID, p)
|
||||||
|
ret = filesys.DocIAL(filePath)
|
||||||
filelock.Lock(filePath)
|
|
||||||
file, err := os.Open(filePath)
|
|
||||||
if err != nil {
|
|
||||||
logging.LogErrorf("open file [%s] failed: %s", p, err)
|
|
||||||
filelock.Unlock(filePath)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
filelock.Unlock(filePath)
|
|
||||||
|
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
logging.LogWarnf("properties not found in file [%s]", p)
|
logging.LogWarnf("properties not found in file [%s]", filePath)
|
||||||
box.moveCorruptedData(filePath)
|
box.moveCorruptedData(filePath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue