mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-26 03:18:48 +01:00
🧑💻 Improve internal kernel API /api/attr/batchSetBlockAttrs Fix https://github.com/siyuan-note/siyuan/issues/10401
This commit is contained in:
parent
d81c7f2609
commit
fbbf83b52d
1 changed files with 19 additions and 4 deletions
|
|
@ -104,25 +104,34 @@ func BatchSetBlockAttrs(blockAttrs []map[string]interface{}) (err error) {
|
|||
trees := map[string]*parse.Tree{}
|
||||
for _, blockAttr := range blockAttrs {
|
||||
id := blockAttr["id"].(string)
|
||||
if nil == trees[id] {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
}
|
||||
|
||||
if nil == trees[bt.RootID] {
|
||||
tree, e := loadTreeByBlockID(id)
|
||||
if nil != e {
|
||||
return e
|
||||
}
|
||||
trees[id] = tree
|
||||
trees[bt.RootID] = tree
|
||||
}
|
||||
}
|
||||
|
||||
var nodes []*ast.Node
|
||||
for _, blockAttr := range blockAttrs {
|
||||
id := blockAttr["id"].(string)
|
||||
attrs := blockAttr["attrs"].(map[string]string)
|
||||
tree := trees[id]
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
}
|
||||
tree := trees[bt.RootID]
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
}
|
||||
|
||||
attrs := blockAttr["attrs"].(map[string]string)
|
||||
oldAttrs, e := setNodeAttrs0(node, attrs)
|
||||
if nil != e {
|
||||
return e
|
||||
|
|
@ -133,6 +142,12 @@ func BatchSetBlockAttrs(blockAttrs []map[string]interface{}) (err error) {
|
|||
nodes = append(nodes, node)
|
||||
}
|
||||
|
||||
for _, tree := range trees {
|
||||
if err = indexWriteJSONQueue(tree); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
IncSync()
|
||||
// 不做锚文本刷新
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue