mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 13:00:57 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
cabe855372
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/siyuan-note/siyuan/kernel/model"
|
"github.com/siyuan-note/siyuan/kernel/model"
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
@ -48,7 +49,7 @@ func batchGetBlockAttrs(c *gin.Context) {
|
|||||||
idList = append(idList, id.(string))
|
idList = append(idList, id.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = model.BatchGetBlockAttrs(idList)
|
ret.Data = sql.BatchGetBlockAttrs(idList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBlockAttrs(c *gin.Context) {
|
func getBlockAttrs(c *gin.Context) {
|
||||||
@ -65,7 +66,7 @@ func getBlockAttrs(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = model.GetBlockAttrs(id)
|
ret.Data = sql.GetBlockAttrs(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setBlockAttrs(c *gin.Context) {
|
func setBlockAttrs(c *gin.Context) {
|
||||||
|
@ -493,7 +493,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||||||
waitForSyncingStorages()
|
waitForSyncingStorages()
|
||||||
|
|
||||||
ret = []*BlockAttributeViewKeys{}
|
ret = []*BlockAttributeViewKeys{}
|
||||||
attrs := GetBlockAttrsWithoutWaitWriting(blockID)
|
attrs := sql.GetBlockAttrs(blockID)
|
||||||
avs := attrs[av.NodeAttrNameAvs]
|
avs := attrs[av.NodeAttrNameAvs]
|
||||||
if "" == avs {
|
if "" == avs {
|
||||||
return
|
return
|
||||||
@ -631,7 +631,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||||||
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
|
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
|
||||||
}
|
}
|
||||||
case av.KeyTypeUpdated:
|
case av.KeyTypeUpdated:
|
||||||
ial := GetBlockAttrsWithoutWaitWriting(blockID)
|
ial := sql.GetBlockAttrs(blockID)
|
||||||
updatedStr := ial["updated"]
|
updatedStr := ial["updated"]
|
||||||
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
|
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
|
||||||
if nil == parseErr {
|
if nil == parseErr {
|
||||||
@ -655,7 +655,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||||||
ial := map[string]string{}
|
ial := map[string]string{}
|
||||||
block := av.GetKeyBlockValue(keyValues)
|
block := av.GetKeyBlockValue(keyValues)
|
||||||
if nil != block && !block.IsDetached {
|
if nil != block && !block.IsDetached {
|
||||||
ial = GetBlockAttrsWithoutWaitWriting(block.BlockID)
|
ial = sql.GetBlockAttrs(block.BlockID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == kv.Values[0].Template {
|
if nil == kv.Values[0].Template {
|
||||||
@ -965,7 +965,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|||||||
}
|
}
|
||||||
view.Table.Sorts = tmpSorts
|
view.Table.Sorts = tmpSorts
|
||||||
|
|
||||||
viewable = sql.RenderAttributeViewTable(attrView, view, query, GetBlockAttrsWithoutWaitWriting)
|
viewable = sql.RenderAttributeViewTable(attrView, view, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewable.FilterRows(attrView)
|
viewable.FilterRows(attrView)
|
||||||
@ -2008,7 +2008,7 @@ func addAttributeViewBlock(now int64, avID, blockID, previousBlockID, addingBloc
|
|||||||
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
||||||
view, _ := getAttrViewViewByBlockID(attrView, blockID)
|
view, _ := getAttrViewViewByBlockID(attrView, blockID)
|
||||||
if nil != view && 0 < len(view.Table.Filters) && !ignoreFillFilter {
|
if nil != view && 0 < len(view.Table.Filters) && !ignoreFillFilter {
|
||||||
viewable := sql.RenderAttributeViewTable(attrView, view, "", GetBlockAttrsWithoutWaitWriting)
|
viewable := sql.RenderAttributeViewTable(attrView, view, "")
|
||||||
viewable.FilterRows(attrView)
|
viewable.FilterRows(attrView)
|
||||||
viewable.SortRows(attrView)
|
viewable.SortRows(attrView)
|
||||||
|
|
||||||
|
@ -24,13 +24,10 @@ import (
|
|||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/html"
|
|
||||||
"github.com/88250/lute/lex"
|
"github.com/88250/lute/lex"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"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"
|
||||||
@ -53,7 +50,9 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||||||
timedMills = t.UnixMilli()
|
timedMills = t.UnixMilli()
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs := GetBlockAttrs(id) // 获取属性是会等待树写入
|
WaitForWritingFiles()
|
||||||
|
|
||||||
|
attrs := sql.GetBlockAttrs(id)
|
||||||
tree, err := LoadTreeByBlockID(id)
|
tree, err := LoadTreeByBlockID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -67,7 +66,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||||||
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
||||||
node = treenode.FirstLeafBlock(node)
|
node = treenode.FirstLeafBlock(node)
|
||||||
}
|
}
|
||||||
content := sql.NodeStaticContent(node, nil, false, false, false, GetBlockAttrsWithoutWaitWriting)
|
content := sql.NodeStaticContent(node, nil, false, false, false)
|
||||||
content = gulu.Str.SubStr(content, 128)
|
content = gulu.Str.SubStr(content, 128)
|
||||||
err = SetCloudBlockReminder(id, content, timedMills)
|
err = SetCloudBlockReminder(id, content, timedMills)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -285,72 +284,3 @@ func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||||||
cache.RemoveBlockIAL(id)
|
cache.RemoveBlockIAL(id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
|
|
||||||
WaitForWritingFiles()
|
|
||||||
|
|
||||||
ret = map[string]map[string]string{}
|
|
||||||
trees := filesys.LoadTrees(ids)
|
|
||||||
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) {
|
|
||||||
ret = map[string]string{}
|
|
||||||
if cached := cache.GetBlockIAL(id); nil != cached {
|
|
||||||
ret = cached
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitForWritingFiles()
|
|
||||||
|
|
||||||
ret = getBlockAttrs(id)
|
|
||||||
cache.PutBlockIAL(id, ret)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetBlockAttrsWithoutWaitWriting(id string) (ret map[string]string) {
|
|
||||||
ret = map[string]string{}
|
|
||||||
if cached := cache.GetBlockIAL(id); nil != cached {
|
|
||||||
ret = cached
|
|
||||||
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)
|
|
||||||
if err != nil {
|
|
||||||
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)
|
|
||||||
if nil == node {
|
|
||||||
logging.LogWarnf("block [%s] not found", id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range node.KramdownIAL {
|
|
||||||
ret[kv[0]] = html.UnescapeAttrVal(kv[1])
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -77,7 +77,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := util.FilterFileName(getAttrViewName(attrView))
|
name := util.FilterFileName(getAttrViewName(attrView))
|
||||||
table := sql.RenderAttributeViewTable(attrView, view, "", GetBlockAttrsWithoutWaitWriting)
|
table := sql.RenderAttributeViewTable(attrView, view, "")
|
||||||
|
|
||||||
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||||
table.FilterRows(attrView)
|
table.FilterRows(attrView)
|
||||||
@ -2256,7 +2256,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
table := sql.RenderAttributeViewTable(attrView, view, "", GetBlockAttrsWithoutWaitWriting)
|
table := sql.RenderAttributeViewTable(attrView, view, "")
|
||||||
|
|
||||||
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||||
table.FilterRows(attrView)
|
table.FilterRows(attrView)
|
||||||
@ -3061,7 +3061,7 @@ func getDestViewVal(attrView *av.AttributeView, keyID, blockID string) *av.Table
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
destTable := sql.RenderAttributeViewTable(destAv, destView, "", GetBlockAttrsWithoutWaitWriting)
|
destTable := sql.RenderAttributeViewTable(destAv, destView, "")
|
||||||
if nil == destTable {
|
if nil == destTable {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -598,7 +598,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
|
|||||||
newCardLimit := Conf.Flashcard.NewCardLimit
|
newCardLimit := Conf.Flashcard.NewCardLimit
|
||||||
reviewCardLimit := Conf.Flashcard.ReviewCardLimit
|
reviewCardLimit := Conf.Flashcard.ReviewCardLimit
|
||||||
// 文档级新卡/复习卡上限控制 Document-level new card/review card limit control https://github.com/siyuan-note/siyuan/issues/9365
|
// 文档级新卡/复习卡上限控制 Document-level new card/review card limit control https://github.com/siyuan-note/siyuan/issues/9365
|
||||||
ial := GetBlockAttrs(rootID)
|
ial := sql.GetBlockAttrs(rootID)
|
||||||
if newCardLimitStr := ial["custom-riff-new-card-limit"]; "" != newCardLimitStr {
|
if newCardLimitStr := ial["custom-riff-new-card-limit"]; "" != newCardLimitStr {
|
||||||
var convertErr error
|
var convertErr error
|
||||||
newCardLimit, convertErr = strconv.Atoi(newCardLimitStr)
|
newCardLimit, convertErr = strconv.Atoi(newCardLimitStr)
|
||||||
|
@ -97,7 +97,7 @@ func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sql.NodeStaticContent(node, excludeTypes, false, false, false, GetBlockAttrsWithoutWaitWriting)
|
ret = sql.NodeStaticContent(node, excludeTypes, false, false, false)
|
||||||
ret = strings.TrimSpace(ret)
|
ret = strings.TrimSpace(ret)
|
||||||
ret = strings.ReplaceAll(ret, "\n", "")
|
ret = strings.ReplaceAll(ret, "\n", "")
|
||||||
ret = util.EscapeHTML(ret)
|
ret = util.EscapeHTML(ret)
|
||||||
@ -160,7 +160,7 @@ func renderBlockContentByNodes(nodes []*ast.Node) string {
|
|||||||
|
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
for _, n := range subNodes {
|
for _, n := range subNodes {
|
||||||
buf.WriteString(sql.NodeStaticContent(n, nil, false, false, false, GetBlockAttrsWithoutWaitWriting))
|
buf.WriteString(sql.NodeStaticContent(n, nil, false, false, false))
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
table := sql.RenderAttributeViewTable(attrView, view, "", GetBlockAttrsWithoutWaitWriting)
|
table := sql.RenderAttributeViewTable(attrView, view, "")
|
||||||
|
|
||||||
var aligns []int
|
var aligns []int
|
||||||
for range table.Columns {
|
for range table.Columns {
|
||||||
|
@ -52,7 +52,7 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
content := sql.NodeStaticContent(n, nil, false, false, false, GetBlockAttrsWithoutWaitWriting)
|
content := sql.NodeStaticContent(n, nil, false, false, false)
|
||||||
buf.WriteString(content)
|
buf.WriteString(content)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
@ -27,23 +27,11 @@ import (
|
|||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string,
|
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
|
||||||
GetBlockAttrsWithoutWaitWriting func(id string) (ret map[string]string)) (ret *av.Table) {
|
|
||||||
if nil == GetBlockAttrsWithoutWaitWriting {
|
|
||||||
GetBlockAttrsWithoutWaitWriting = func(id string) (ret map[string]string) {
|
|
||||||
ret = cache.GetBlockIAL(id)
|
|
||||||
if nil == ret {
|
|
||||||
ret = map[string]string{}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = &av.Table{
|
ret = &av.Table{
|
||||||
ID: view.ID,
|
ID: view.ID,
|
||||||
Icon: view.Icon,
|
Icon: view.Icon,
|
||||||
@ -281,7 +269,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||||||
ial := map[string]string{}
|
ial := map[string]string{}
|
||||||
block := row.GetBlockValue()
|
block := row.GetBlockValue()
|
||||||
if nil != block && !block.IsDetached {
|
if nil != block && !block.IsDetached {
|
||||||
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
|
ial = GetBlockAttrs(row.ID)
|
||||||
}
|
}
|
||||||
updatedStr := ial["updated"]
|
updatedStr := ial["updated"]
|
||||||
if "" == updatedStr && nil != block {
|
if "" == updatedStr && nil != block {
|
||||||
@ -317,7 +305,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||||||
ial := map[string]string{}
|
ial := map[string]string{}
|
||||||
block := row.GetBlockValue()
|
block := row.GetBlockValue()
|
||||||
if nil != block && !block.IsDetached {
|
if nil != block && !block.IsDetached {
|
||||||
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
|
ial = GetBlockAttrs(row.ID)
|
||||||
}
|
}
|
||||||
content, renderErr := RenderTemplateCol(ial, keyValues, cell.Value.Template.Content)
|
content, renderErr := RenderTemplateCol(ial, keyValues, cell.Value.Template.Content)
|
||||||
cell.Value.Template.Content = content
|
cell.Value.Template.Content = content
|
||||||
@ -568,8 +556,7 @@ func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttributeViewContent(avID string,
|
func getAttributeViewContent(avID string) (content string) {
|
||||||
GetBlockAttrsWithoutWaitWriting func(id string) (ret map[string]string)) (content string) {
|
|
||||||
if "" == avID {
|
if "" == avID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -605,7 +592,7 @@ func getAttributeViewContent(avID string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
table := RenderAttributeViewTable(attrView, view, "", GetBlockAttrsWithoutWaitWriting)
|
table := RenderAttributeViewTable(attrView, view, "")
|
||||||
for _, col := range table.Columns {
|
for _, col := range table.Columns {
|
||||||
buf.WriteString(col.Name)
|
buf.WriteString(col.Name)
|
||||||
buf.WriteByte(' ')
|
buf.WriteByte(' ')
|
||||||
|
@ -24,6 +24,8 @@ import (
|
|||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"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/filesys"
|
||||||
@ -104,7 +106,6 @@ func indexNode(tx *sql.Tx, id string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
luteEngine := util.NewLute()
|
|
||||||
tree, _ := filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
tree, _ := filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
return
|
return
|
||||||
@ -115,7 +116,7 @@ func indexNode(tx *sql.Tx, id string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content := NodeStaticContent(node, nil, true, indexAssetPath, true, nil)
|
content := NodeStaticContent(node, nil, true, indexAssetPath, true)
|
||||||
stmt := "UPDATE blocks SET content = ? WHERE id = ?"
|
stmt := "UPDATE blocks SET content = ? WHERE id = ?"
|
||||||
if err = execStmtTx(tx, stmt, content, id); err != nil {
|
if err = execStmtTx(tx, stmt, content, id); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -136,15 +137,14 @@ func indexNode(tx *sql.Tx, id string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool,
|
func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string {
|
||||||
GetBlockAttrsWithoutWaitWriting func(id string) (ret map[string]string)) string {
|
|
||||||
if nil == node {
|
if nil == node {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if ast.NodeAttributeView == node.Type {
|
if ast.NodeAttributeView == node.Type {
|
||||||
if fullAttrView {
|
if fullAttrView {
|
||||||
return getAttributeViewContent(node.AttributeViewID, GetBlockAttrsWithoutWaitWriting)
|
return getAttributeViewContent(node.AttributeViewID)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, _ := av.GetAttributeViewName(node.AttributeViewID)
|
ret, _ := av.GetAttributeViewName(node.AttributeViewID)
|
||||||
@ -274,3 +274,63 @@ func nodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||||||
// Improve search and replace for spaces https://github.com/siyuan-note/siyuan/issues/10231
|
// Improve search and replace for spaces https://github.com/siyuan-note/siyuan/issues/10231
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
|
||||||
|
ret = map[string]map[string]string{}
|
||||||
|
trees := filesys.LoadTrees(ids)
|
||||||
|
for _, id := range ids {
|
||||||
|
tree := trees[id]
|
||||||
|
if nil == tree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[id] = getBlockAttrsFromTree(id, tree)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBlockAttrs(id string) (ret map[string]string) {
|
||||||
|
ret = map[string]string{}
|
||||||
|
|
||||||
|
ret = map[string]string{}
|
||||||
|
if cached := cache.GetBlockIAL(id); nil != cached {
|
||||||
|
ret = cached
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tree := loadTreeByBlockID(id)
|
||||||
|
if nil == tree {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = getBlockAttrsFromTree(id, tree)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBlockAttrsFromTree(id string, tree *parse.Tree) (ret map[string]string) {
|
||||||
|
ret = map[string]string{}
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
cache.PutBlockIAL(id, ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadTreeByBlockID(id string) (ret *parse.Tree) {
|
||||||
|
bt := treenode.GetBlockTree(id)
|
||||||
|
if nil == bt {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, err := filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -828,13 +828,13 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
|||||||
if !treenode.IsNodeOCRed(n) {
|
if !treenode.IsNodeOCRed(n) {
|
||||||
util.PushNodeOCRQueue(n)
|
util.PushNodeOCRQueue(n)
|
||||||
}
|
}
|
||||||
content = NodeStaticContent(n, nil, true, indexAssetPath, true, nil)
|
content = NodeStaticContent(n, nil, true, indexAssetPath, true)
|
||||||
|
|
||||||
fc := treenode.FirstLeafBlock(n)
|
fc := treenode.FirstLeafBlock(n)
|
||||||
if !treenode.IsNodeOCRed(fc) {
|
if !treenode.IsNodeOCRed(fc) {
|
||||||
util.PushNodeOCRQueue(fc)
|
util.PushNodeOCRQueue(fc)
|
||||||
}
|
}
|
||||||
fcontent = NodeStaticContent(fc, nil, true, false, true, nil)
|
fcontent = NodeStaticContent(fc, nil, true, false, true)
|
||||||
|
|
||||||
parentID = n.Parent.ID
|
parentID = n.Parent.ID
|
||||||
if h := heading(n); nil != h { // 如果在标题块下方,则将标题块作为父节点
|
if h := heading(n); nil != h { // 如果在标题块下方,则将标题块作为父节点
|
||||||
@ -846,7 +846,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
|||||||
if !treenode.IsNodeOCRed(n) {
|
if !treenode.IsNodeOCRed(n) {
|
||||||
util.PushNodeOCRQueue(n)
|
util.PushNodeOCRQueue(n)
|
||||||
}
|
}
|
||||||
content = NodeStaticContent(n, nil, true, indexAssetPath, true, nil)
|
content = NodeStaticContent(n, nil, true, indexAssetPath, true)
|
||||||
|
|
||||||
parentID = n.Parent.ID
|
parentID = n.Parent.ID
|
||||||
if h := heading(n); nil != h {
|
if h := heading(n); nil != h {
|
||||||
|
Loading…
Reference in New Issue
Block a user