mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-19 23:06:09 +01:00
⚡ 改进多个功能点的性能 https://github.com/siyuan-note/siyuan/issues/7177
This commit is contained in:
parent
5da5ae8818
commit
2b09ea75f0
7 changed files with 56 additions and 63 deletions
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -383,31 +382,33 @@ func GetBlockKramdown(id string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetBlock(id string) (ret *Block, err error) {
|
||||
ret, err = getBlock(id)
|
||||
func GetBlock(id string, tree *parse.Tree) (ret *Block, err error) {
|
||||
ret, err = getBlock(id, tree)
|
||||
return
|
||||
}
|
||||
|
||||
func getBlock(id string) (ret *Block, err error) {
|
||||
func getBlock(id string, tree *parse.Tree) (ret *Block, err error) {
|
||||
if "" == id {
|
||||
return
|
||||
}
|
||||
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if task.ContainIndexTask() {
|
||||
err = ErrIndexing
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
if nil == tree {
|
||||
tree, err = loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
return
|
||||
time.Sleep(1 * time.Second)
|
||||
tree, err = loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
|
||||
sqlBlock := sql.BuildBlockFromNode(node, tree)
|
||||
if nil == sqlBlock {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -892,18 +892,12 @@ func renameWriteJSONQueue(tree *parse.Tree, oldHPath string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func DuplicateDoc(rootID string) (ret *parse.Tree, err error) {
|
||||
func DuplicateDoc(tree *parse.Tree) {
|
||||
msgId := util.PushMsg(Conf.Language(116), 30000)
|
||||
defer util.PushClearMsg(msgId)
|
||||
|
||||
WaitForWritingFiles()
|
||||
ret, err = loadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
resetTree(ret, "Duplicated")
|
||||
createTreeTx(ret)
|
||||
resetTree(tree, "Duplicated")
|
||||
createTreeTx(tree)
|
||||
WaitForWritingFiles()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -145,6 +146,10 @@ var (
|
|||
ErrIndexing = errors.New("indexing")
|
||||
)
|
||||
|
||||
func LoadTreeByID(id string) (ret *parse.Tree, err error) {
|
||||
return loadTreeByBlockID(id)
|
||||
}
|
||||
|
||||
func loadTreeByBlockID(id string) (ret *parse.Tree, err error) {
|
||||
if "" == id {
|
||||
return nil, ErrTreeNotFound
|
||||
|
|
@ -152,6 +157,11 @@ func loadTreeByBlockID(id string) (ret *parse.Tree, err error) {
|
|||
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
if task.ContainIndexTask() {
|
||||
err = ErrIndexing
|
||||
return
|
||||
}
|
||||
|
||||
return nil, ErrBlockNotFound
|
||||
}
|
||||
ret, err = LoadTree(bt.BoxID, bt.Path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue