From fbbf83b52d463d4af2bbfc2a9f97e76f70177512 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 23 Feb 2024 10:41:19 +0800 Subject: [PATCH] :technologist: Improve internal kernel API `/api/attr/batchSetBlockAttrs` Fix https://github.com/siyuan-note/siyuan/issues/10401 --- kernel/model/blockial.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/kernel/model/blockial.go b/kernel/model/blockial.go index 49f98b609..c0fa6c5ec 100644 --- a/kernel/model/blockial.go +++ b/kernel/model/blockial.go @@ -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