|
@@ -30,6 +30,7 @@ import (
|
|
"github.com/araddon/dateparse"
|
|
"github.com/araddon/dateparse"
|
|
"github.com/siyuan-note/logging"
|
|
"github.com/siyuan-note/logging"
|
|
"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"
|
|
@@ -287,6 +288,36 @@ func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
|
|
|
|
+ WaitForWritingFiles()
|
|
|
|
+
|
|
|
|
+ ret = map[string]map[string]string{}
|
|
|
|
+ trees := map[string]*parse.Tree{}
|
|
|
|
+ bts := treenode.GetBlockTrees(ids)
|
|
|
|
+ luteEngine := util.NewLute()
|
|
|
|
+ for id, bt := range bts {
|
|
|
|
+ if nil == trees[id] {
|
|
|
|
+ tree, err := filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
|
|
|
+ if nil != err {
|
|
|
|
+ logging.LogErrorf("load tree [%s] failed: %s", bt.Path, err)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ trees[id] = tree
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, id := range ids {
|
|
|
|
+ tree := trees[id]
|
|
|
|
+ if nil == tree {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret[id] = getBlockAttrs0(id, tree)
|
|
|
|
+ cache.PutBlockIAL(id, ret[id])
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func GetBlockAttrs(id string) (ret map[string]string) {
|
|
func GetBlockAttrs(id string) (ret map[string]string) {
|
|
ret = map[string]string{}
|
|
ret = map[string]string{}
|
|
if cached := cache.GetBlockIAL(id); nil != cached {
|
|
if cached := cache.GetBlockIAL(id); nil != cached {
|
|
@@ -296,20 +327,7 @@ func GetBlockAttrs(id string) (ret map[string]string) {
|
|
|
|
|
|
WaitForWritingFiles()
|
|
WaitForWritingFiles()
|
|
|
|
|
|
- tree, err := LoadTreeByBlockID(id)
|
|
|
|
- if nil != err {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- node := treenode.GetNodeInTree(tree, id)
|
|
|
|
- if nil == node {
|
|
|
|
- logging.LogWarnf("block [%s] not found", id)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for _, kv := range node.KramdownIAL {
|
|
|
|
- ret[kv[0]] = html.UnescapeAttrVal(kv[1])
|
|
|
|
- }
|
|
|
|
|
|
+ ret = getBlockAttrs(id)
|
|
cache.PutBlockIAL(id, ret)
|
|
cache.PutBlockIAL(id, ret)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -321,11 +339,25 @@ func GetBlockAttrsWithoutWaitWriting(id string) (ret map[string]string) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ret = getBlockAttrs(id)
|
|
|
|
+ cache.PutBlockIAL(id, ret)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getBlockAttrs(id string) (ret map[string]string) {
|
|
|
|
+ ret = map[string]string{}
|
|
|
|
+
|
|
tree, err := LoadTreeByBlockID(id)
|
|
tree, err := LoadTreeByBlockID(id)
|
|
if nil != err {
|
|
if nil != err {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ret = getBlockAttrs0(id, tree)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getBlockAttrs0(id string, tree *parse.Tree) (ret map[string]string) {
|
|
|
|
+ ret = map[string]string{}
|
|
node := treenode.GetNodeInTree(tree, id)
|
|
node := treenode.GetNodeInTree(tree, id)
|
|
if nil == node {
|
|
if nil == node {
|
|
logging.LogWarnf("block [%s] not found", id)
|
|
logging.LogWarnf("block [%s] not found", id)
|
|
@@ -335,6 +367,5 @@ func GetBlockAttrsWithoutWaitWriting(id string) (ret map[string]string) {
|
|
for _, kv := range node.KramdownIAL {
|
|
for _, kv := range node.KramdownIAL {
|
|
ret[kv[0]] = html.UnescapeAttrVal(kv[1])
|
|
ret[kv[0]] = html.UnescapeAttrVal(kv[1])
|
|
}
|
|
}
|
|
- cache.PutBlockIAL(id, ret)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|