mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
⚡ Improve performance for batch set block attrs
This commit is contained in:
parent
fe8520d1ac
commit
4f07f3314a
1 changed files with 8 additions and 17 deletions
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
|
|
@ -101,31 +102,21 @@ func BatchSetBlockAttrs(blockAttrs []map[string]interface{}) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
trees := map[string]*parse.Tree{}
|
|
||||||
for _, blockAttr := range blockAttrs {
|
|
||||||
id := blockAttr["id"].(string)
|
|
||||||
bt := treenode.GetBlockTree(id)
|
|
||||||
if nil == bt {
|
|
||||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
|
||||||
}
|
|
||||||
|
|
||||||
if nil == trees[bt.RootID] {
|
var blockIDs []string
|
||||||
tree, e := LoadTreeByBlockID(id)
|
for _, blockAttr := range blockAttrs {
|
||||||
if nil != e {
|
blockIDs = append(blockIDs, blockAttr["id"].(string))
|
||||||
return e
|
|
||||||
}
|
|
||||||
trees[bt.RootID] = tree
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trees := filesys.LoadTrees(blockIDs)
|
||||||
var nodes []*ast.Node
|
var nodes []*ast.Node
|
||||||
for _, blockAttr := range blockAttrs {
|
for _, blockAttr := range blockAttrs {
|
||||||
id := blockAttr["id"].(string)
|
id := blockAttr["id"].(string)
|
||||||
bt := treenode.GetBlockTree(id)
|
tree := trees[id]
|
||||||
if nil == bt {
|
if nil == tree {
|
||||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||||
}
|
}
|
||||||
tree := trees[bt.RootID]
|
|
||||||
node := treenode.GetNodeInTree(tree, id)
|
node := treenode.GetNodeInTree(tree, id)
|
||||||
if nil == node {
|
if nil == node {
|
||||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue