改进重命名资源文件性能 Fix https://github.com/siyuan-note/siyuan/issues/7322

This commit is contained in:
Liang Ding 2023-02-10 12:05:56 +08:00
parent 929a25a783
commit 6743b21193
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 12 additions and 5 deletions

View file

@ -42,6 +42,12 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
if nil != err {
return
}
ret, err = LoadTreeByData(data, boxID, p, luteEngine)
return
}
func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
ret = parseJSON2Tree(boxID, p, data, luteEngine)
if nil == ret {
return nil, errors.New("parse tree failed")
@ -88,7 +94,7 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
ial := ReadDocIAL(parentData)
if 1 > len(ial) {
logging.LogWarnf("tree [%s] is corrupted", filePath)
logging.LogWarnf("tree [%s] is corrupted", filepath.Join(boxID, p))
}
title := ial["title"]
if "" == title {

View file

@ -40,6 +40,7 @@ import (
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -503,6 +504,7 @@ func RenameAsset(oldPath, newName string) (err error) {
return
}
luteEngine := NewLute()
for _, notebook := range notebooks {
pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32)
@ -528,11 +530,10 @@ func RenameAsset(oldPath, newName string) (err error) {
}
p := filepath.ToSlash(strings.TrimPrefix(treeAbsPath, filepath.Join(util.DataDir, notebook.ID)))
tree, parseErr := LoadTree(notebook.ID, p)
tree, parseErr := filesys.LoadTreeByData(data, notebook.ID, p, luteEngine)
if nil != parseErr {
logging.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr)
err = parseErr
return
logging.LogWarnf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr)
continue
}
treenode.IndexBlockTree(tree)