mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
⚡ Improve database loading performance https://github.com/siyuan-note/siyuan/issues/15115
This commit is contained in:
parent
2e2f152311
commit
17369d28c9
3 changed files with 47 additions and 11 deletions
|
|
@ -41,6 +41,10 @@ import (
|
||||||
|
|
||||||
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
|
||||||
ret = map[string]*parse.Tree{}
|
ret = map[string]*parse.Tree{}
|
||||||
|
if 1 > len(ids) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
bts := treenode.GetBlockTrees(ids)
|
bts := treenode.GetBlockTrees(ids)
|
||||||
luteEngine := util.NewLute()
|
luteEngine := util.NewLute()
|
||||||
var boxIDs []string
|
var boxIDs []string
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/88250/lute/render"
|
"github.com/88250/lute/render"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"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/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
@ -66,6 +67,16 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
cardsValues := generateAttrViewItems(attrView) // 生成卡片
|
cardsValues := generateAttrViewItems(attrView) // 生成卡片
|
||||||
filterNotFoundAttrViewItems(&cardsValues) // 过滤掉不存在的卡片
|
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 {
|
for cardID, cardValues := range cardsValues {
|
||||||
var galleryCard av.GalleryCard
|
var galleryCard av.GalleryCard
|
||||||
|
|
@ -97,19 +108,12 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
galleryCard.Values = append(galleryCard.Values, fieldValue)
|
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)
|
ret.Cards = append(ret.Cards, &galleryCard)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量获取块属性以提升性能
|
// 批量获取块属性以提升性能
|
||||||
var ialIDs []string
|
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
||||||
for _, card := range ret.Cards {
|
|
||||||
block := card.GetBlockValue()
|
|
||||||
if nil != block && !block.IsDetached {
|
|
||||||
ialIDs = append(ialIDs, card.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ials := BatchGetBlockAttrs(ialIDs)
|
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
|
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
|
||||||
avCache := map[string]*av.AttributeView{}
|
avCache := map[string]*av.AttributeView{}
|
||||||
|
|
@ -139,7 +143,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
return
|
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 {
|
switch view.Gallery.CoverFrom {
|
||||||
case av.CoverFromNone:
|
case av.CoverFromNone:
|
||||||
case av.CoverFromContentImage:
|
case av.CoverFromContentImage:
|
||||||
|
|
@ -148,7 +152,7 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
tree := loadTreeByBlockID(blockValue.BlockID)
|
tree := trees[blockValue.BlockID]
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,34 @@ func nodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
||||||
return buf.String()
|
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) {
|
func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {
|
||||||
ret = map[string]map[string]string{}
|
ret = map[string]map[string]string{}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue