mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Improve database performance https://github.com/siyuan-note/siyuan/issues/15764
This commit is contained in:
parent
cd8c3a41e6
commit
2b85cb1b6c
4 changed files with 21 additions and 10 deletions
|
|
@ -42,6 +42,8 @@ type AttributeView struct {
|
||||||
KeyIDs []string `json:"keyIDs"` // 属性视图属性键 ID,用于排序
|
KeyIDs []string `json:"keyIDs"` // 属性视图属性键 ID,用于排序
|
||||||
ViewID string `json:"viewID"` // 当前视图 ID
|
ViewID string `json:"viewID"` // 当前视图 ID
|
||||||
Views []*View `json:"views"` // 视图
|
Views []*View `json:"views"` // 视图
|
||||||
|
|
||||||
|
RenderedViewables map[string]Viewable `json:"-"` // 已经渲染好的视图
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyValues 描述了属性视图属性键值列表的结构。
|
// KeyValues 描述了属性视图属性键值列表的结构。
|
||||||
|
|
@ -428,7 +430,7 @@ func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = &AttributeView{}
|
ret = &AttributeView{RenderedViewables: map[string]Viewable{}}
|
||||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||||
if strings.Contains(err.Error(), ".relation.contents of type av.Value") {
|
if strings.Contains(err.Error(), ".relation.contents of type av.Value") {
|
||||||
mapAv := map[string]interface{}{}
|
mapAv := map[string]interface{}{}
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,12 @@ func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av
|
||||||
renderedAttrViews := map[string]*av.AttributeView{}
|
renderedAttrViews := map[string]*av.AttributeView{}
|
||||||
renderedAttrViews[attrView.ID] = attrView
|
renderedAttrViews[attrView.ID] = attrView
|
||||||
ret = renderView(attrView, view, query, &depth, renderedAttrViews)
|
ret = renderView(attrView, view, query, &depth, renderedAttrViews)
|
||||||
|
|
||||||
|
attrView.RenderedViewables[ret.GetID()] = ret
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderView(attrView *av.AttributeView, view *av.View, query string,
|
func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int, cachedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
|
||||||
depth *int, cachedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
|
|
||||||
if 7 < *depth {
|
if 7 < *depth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -334,9 +335,7 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string,
|
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, depth *int, cachedAttrViews map[string]*av.AttributeView) {
|
||||||
depth *int, cachedAttrViews map[string]*av.AttributeView) {
|
|
||||||
|
|
||||||
// 先渲染主键、创建时间、更新时间
|
// 先渲染主键、创建时间、更新时间
|
||||||
|
|
||||||
for _, item := range collection.GetItems() {
|
for _, item := range collection.GetItems() {
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,13 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string,
|
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string, depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Gallery) {
|
||||||
depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Gallery) {
|
viewable := attrView.RenderedViewables[view.ID]
|
||||||
|
if nil != viewable {
|
||||||
|
ret = viewable.(*av.Gallery)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ret = &av.Gallery{
|
ret = &av.Gallery{
|
||||||
BaseInstance: av.NewViewBaseInstance(view),
|
BaseInstance: av.NewViewBaseInstance(view),
|
||||||
CoverFrom: view.Gallery.CoverFrom,
|
CoverFrom: view.Gallery.CoverFrom,
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,13 @@ import (
|
||||||
"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, depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Table) {
|
||||||
depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Table) {
|
viewable := attrView.RenderedViewables[view.ID]
|
||||||
|
if nil != viewable {
|
||||||
|
ret = viewable.(*av.Table)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ret = &av.Table{
|
ret = &av.Table{
|
||||||
BaseInstance: av.NewViewBaseInstance(view),
|
BaseInstance: av.NewViewBaseInstance(view),
|
||||||
Columns: []*av.TableColumn{},
|
Columns: []*av.TableColumn{},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue