Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: The database rollup field supports using the template field https://github.com/siyuan-note/siyuan/issues/12384

Danielf2dda8b389b7
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 4f3a7df7e6..65e1fb8e9a 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -3422,7 +3422,9 @@ func getAttrViewTable(attrView *av.AttributeView, view *av.View, query string) (
view.Table.Columns = append(view.Table.Columns, &av.ViewTableColumn{BaseField: &av.BaseField{ID: field.ID}})
}
}
- ret = sql.RenderAttributeViewTable(attrView, view, query)
+
+ depth := 1
+ ret = sql.RenderAttributeViewTable(attrView, view, query, &depth)
return
}
diff --git a/kernel/sql/av.go b/kernel/sql/av.go
index 5b73fb14a9..8a324ec6c5 100644
--- a/kernel/sql/av.go
+++ b/kernel/sql/av.go
@@ -46,11 +46,20 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
}
func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av.Viewable) {
+ depth := 1
+ return renderView(attrView, view, query, &depth)
+}
+
+func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret av.Viewable) {
+ if 7 < *depth {
+ return
+ }
+
switch view.LayoutType {
case av.LayoutTypeTable:
- ret = RenderAttributeViewTable(attrView, view, query)
+ ret = RenderAttributeViewTable(attrView, view, query, depth)
case av.LayoutTypeGallery:
- ret = RenderAttributeViewGallery(attrView, view, query)
+ ret = RenderAttributeViewGallery(attrView, view, query, depth)
}
return
}
@@ -285,7 +294,7 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID string,
}
}
-func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues) {
+func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues, depth *int) {
avCache := map[string]*av.AttributeView{}
avCache[attrView.ID] = attrView
for _, item := range collection.GetItems() {
@@ -336,12 +345,13 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
var viewable av.Viewable
if av.KeyTypeTemplate == destKey.Type {
- viewable = RenderView(destAv, destAv.Views[0], "")
+ // 渲染目标视图,这样才能汇总渲染后的模板字段值
+ viewable = renderView(destAv, destAv.Views[0], "", depth)
}
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
- if nil == destVal && av.KeyTypeTemplate == destKey.Type && nil != viewable {
+ if nil != viewable && nil == destVal && av.KeyTypeTemplate == destKey.Type {
destVal = viewable.(av.Collection).GetValue(blockID, destKey.ID)
}
diff --git a/kernel/sql/av_gallery.go b/kernel/sql/av_gallery.go
index 22e747a32b..2fe8d977b8 100644
--- a/kernel/sql/av_gallery.go
+++ b/kernel/sql/av_gallery.go
@@ -18,7 +18,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string) (ret *av.Gallery) {
+func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret *av.Gallery) {
ret = &av.Gallery{
BaseInstance: av.NewViewBaseInstance(view),
CoverFrom: view.Gallery.CoverFrom,
@@ -114,7 +114,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
- fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues)
+ fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues, depth)
// 最后单独渲染模板字段,这样模板字段就可以使用汇总、关联、创建时间和更新时间字段的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
diff --git a/kernel/sql/av_table.go b/kernel/sql/av_table.go
index 9e4bab17c7..ef88149eb8 100644
--- a/kernel/sql/av_table.go
+++ b/kernel/sql/av_table.go
@@ -22,7 +22,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
+func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret *av.Table) {
ret = &av.Table{
BaseInstance: av.NewViewBaseInstance(view),
Columns: []*av.TableColumn{},
@@ -107,7 +107,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
ials := BatchGetBlockAttrs(ialIDs)
// 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列
- fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues)
+ fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues, depth)
// 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)