This commit is contained in:
Daniel 2025-06-22 16:55:24 +08:00
parent 2e2f152311
commit 17369d28c9
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 47 additions and 11 deletions

View file

@ -41,6 +41,10 @@ import (
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
ret = map[string]*parse.Tree{}
if 1 > len(ids) {
return ret
}
bts := treenode.GetBlockTrees(ids)
luteEngine := util.NewLute()
var boxIDs []string

View file

@ -10,6 +10,7 @@ import (
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -66,6 +67,16 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
cardsValues := generateAttrViewItems(attrView) // 生成卡片
filterNotFoundAttrViewItems(&cardsValues) // 过滤掉不存在的卡片
// 批量加载绑定块对应的树
var ialIDs []string
for _, card := range ret.Cards {
block := card.GetBlockValue()
if nil != block && !block.IsDetached {
ialIDs = append(ialIDs, card.ID)
}
}
boundTrees := filesys.LoadTrees(ialIDs)
// 生成卡片字段值
for cardID, cardValues := range cardsValues {
var galleryCard av.GalleryCard
@ -97,19 +108,12 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
galleryCard.Values = append(galleryCard.Values, fieldValue)
}
fillAttributeViewGalleryCardCover(attrView, view, cardValues, &galleryCard, cardID, luteEngine)
fillAttributeViewGalleryCardCover(attrView, view, cardValues, &galleryCard, cardID, luteEngine, boundTrees)
ret.Cards = append(ret.Cards, &galleryCard)
}
// 批量获取块属性以提升性能
var ialIDs []string
for _, card := range ret.Cards {
block := card.GetBlockValue()
if nil != block && !block.IsDetached {
ialIDs = append(ialIDs, card.ID)
}
}
ials := BatchGetBlockAttrs(ialIDs)
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
avCache := map[string]*av.AttributeView{}
@ -139,7 +143,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
return
}
func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues []*av.KeyValues, galleryCard *av.GalleryCard, cardID string, luteEngine *lute.Lute) {
func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues []*av.KeyValues, galleryCard *av.GalleryCard, cardID string, luteEngine *lute.Lute, trees map[string]*parse.Tree) {
switch view.Gallery.CoverFrom {
case av.CoverFromNone:
case av.CoverFromContentImage:
@ -148,7 +152,7 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
break
}
tree := loadTreeByBlockID(blockValue.BlockID)
tree := trees[blockValue.BlockID]
if nil == tree {
break
}

View file

@ -276,6 +276,34 @@ func nodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
return buf.String()
}
func BatchGetBlockAttrsWitTrees(ids []string, trees map[string]*parse.Tree) (ret map[string]map[string]string) {
ret = map[string]map[string]string{}
hitCache := true
for _, id := range ids {
ial := cache.GetBlockIAL(id)
if nil != ial {
ret[id] = ial
continue
}
hitCache = false
break
}
if hitCache {
return
}
for _, id := range ids {
tree := trees[id]
if nil == tree {
continue
}
ret[id] = getBlockAttrsFromTree(id, tree)
}
return
}
func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
ret = map[string]map[string]string{}