Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-09-01 12:47:27 +08:00
commit aeb478a6b8
4 changed files with 124 additions and 36 deletions

View file

@ -1536,6 +1536,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
} }
// 先渲染主键、创建时间、更新时间 // 先渲染主键、创建时间、更新时间
for _, kv := range keyValues { for _, kv := range keyValues {
switch kv.Key.Type { switch kv.Key.Type {
case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049 case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
@ -1569,7 +1570,44 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
} }
} }
// 再渲染汇总和关联 // 再渲染关联和汇总
rollupFurtherCollections := map[string]av.Collection{}
for _, kv := range keyValues {
if av.KeyTypeRollup != kv.Key.Type {
continue
}
relKey, _ := attrView.GetKey(kv.Key.Rollup.RelationKeyID)
if nil == relKey {
continue
}
destAv := attrViewCache[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil == destAv {
continue
}
attrViewCache[relKey.Relation.AvID] = destAv
}
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
if nil == destKey {
continue
}
isSameAv := destAv.ID == attrView.ID
var furtherCollection av.Collection
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
viewable := sql.RenderView(destAv, destAv.Views[0], "")
if nil != viewable {
furtherCollection = viewable.(av.Collection)
}
}
rollupFurtherCollections[kv.Key.ID] = furtherCollection
}
for _, kv := range keyValues { for _, kv := range keyValues {
switch kv.Key.Type { switch kv.Key.Type {
case av.KeyTypeRollup: case av.KeyTypeRollup:
@ -1595,15 +1633,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID) destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
if nil != destKey { if nil != destKey {
isSameAv := destAv.ID == attrView.ID furtherCollection := rollupFurtherCollections[kv.Key.ID]
var furtherCollection av.Collection
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
viewable := sql.RenderView(destAv, destAv.Views[0], "")
if nil != viewable {
furtherCollection = viewable.(av.Collection)
}
}
kv.Values[0].Rollup.BuildContents(keyValues, destKey, relVal, kv.Key.Rollup.Calc, furtherCollection) kv.Values[0].Rollup.BuildContents(keyValues, destKey, relVal, kv.Key.Rollup.Calc, furtherCollection)
} }
} }

View file

@ -78,17 +78,17 @@ func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av
} }
func renderView(attrView *av.AttributeView, view *av.View, query string, func renderView(attrView *av.AttributeView, view *av.View, query string,
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret av.Viewable) { depth *int, cachedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
if 7 < *depth { if 2 < *depth {
return return
} }
*depth++ *depth++
switch view.LayoutType { switch view.LayoutType {
case av.LayoutTypeTable: case av.LayoutTypeTable:
ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews) ret = RenderAttributeViewTable(attrView, view, query, depth, cachedAttrViews)
case av.LayoutTypeGallery: case av.LayoutTypeGallery:
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews) ret = RenderAttributeViewGallery(attrView, view, query, depth, cachedAttrViews)
} }
return return
} }
@ -335,9 +335,10 @@ 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, renderedAttrViews map[string]*av.AttributeView) { depth *int, cachedAttrViews map[string]*av.AttributeView) {
// 先渲染主键、创建时间、更新时间 // 先渲染主键、创建时间、更新时间
for _, item := range collection.GetItems() { for _, item := range collection.GetItems() {
for _, value := range item.GetValues() { for _, value := range item.GetValues() {
itemID := item.GetID() itemID := item.GetID()
@ -399,7 +400,54 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
} }
} }
// 再渲染汇总和关联 // 再渲染关联和汇总
rollupFurtherCollections := map[string]av.Collection{}
for _, field := range collection.GetFields() {
if av.KeyTypeRollup != field.GetType() {
continue
}
rollupKey, _ := attrView.GetKey(field.GetID())
if nil == rollupKey || nil == rollupKey.Rollup {
continue
}
relKey, _ := attrView.GetKey(rollupKey.Rollup.RelationKeyID)
if nil == relKey || nil == relKey.Relation {
continue
}
destAv := cachedAttrViews[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv {
cachedAttrViews[relKey.Relation.AvID] = destAv
}
}
if nil == destAv {
continue
}
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
if nil == destKey {
continue
}
isSameAv := destAv.ID == attrView.ID
var furtherCollection av.Collection
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
viewable := renderView(destAv, destAv.Views[0], "", depth, cachedAttrViews)
if nil != viewable {
furtherCollection = viewable.(av.Collection)
} else {
fillAttributeViewTemplateValues(destAv, destAv.Views[0], collection, ials)
furtherCollection = collection
}
}
rollupFurtherCollections[rollupKey.ID] = furtherCollection
}
for _, item := range collection.GetItems() { for _, item := range collection.GetItems() {
for _, value := range item.GetValues() { for _, value := range item.GetValues() {
itemID := item.GetID() itemID := item.GetID()
@ -421,11 +469,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
break break
} }
destAv := renderedAttrViews[relKey.Relation.AvID] destAv := cachedAttrViews[relKey.Relation.AvID]
if nil == destAv { if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID) destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv { if nil != destAv {
renderedAttrViews[relKey.Relation.AvID] = destAv cachedAttrViews[relKey.Relation.AvID] = destAv
} }
} }
if nil == destAv { if nil == destAv {
@ -437,28 +485,17 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
break break
} }
isSameAv := destAv.ID == attrView.ID furtherCollection := rollupFurtherCollections[rollupKey.ID]
var furtherCollection av.Collection
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
viewable := renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews)
if nil != viewable {
furtherCollection = viewable.(av.Collection)
} else {
fillAttributeViewTemplateValues(destAv, destAv.Views[0], collection, ials)
furtherCollection = collection
}
}
value.Rollup.BuildContents(destAv.KeyValues, destKey, relVal, rollupKey.Rollup.Calc, furtherCollection) value.Rollup.BuildContents(destAv.KeyValues, destKey, relVal, rollupKey.Rollup.Calc, furtherCollection)
case av.KeyTypeRelation: // 渲染关联 case av.KeyTypeRelation: // 渲染关联
value.Relation.Contents = nil value.Relation.Contents = nil
relKey, _ := attrView.GetKey(value.KeyID) relKey, _ := attrView.GetKey(value.KeyID)
if nil != relKey && nil != relKey.Relation { if nil != relKey && nil != relKey.Relation {
destAv := renderedAttrViews[relKey.Relation.AvID] destAv := cachedAttrViews[relKey.Relation.AvID]
if nil == destAv { if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID) destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv { if nil != destAv {
renderedAttrViews[relKey.Relation.AvID] = destAv cachedAttrViews[relKey.Relation.AvID] = destAv
} }
} }
if nil != destAv { if nil != destAv {
@ -498,6 +535,10 @@ func fillAttributeViewTemplateValues(attrView *av.AttributeView, view *av.View,
for _, templateKey := range templateKeys { for _, templateKey := range templateKeys {
for _, item := range collection.GetItems() { for _, item := range collection.GetItems() {
value := item.GetValue(templateKey.ID) value := item.GetValue(templateKey.ID)
if nil == value || nil == value.Template {
continue
}
keyValues := items[item.GetID()] keyValues := items[item.GetID()]
var ial map[string]string var ial map[string]string
blockVal := item.GetBlockValue() blockVal := item.GetBlockValue()
@ -550,6 +591,23 @@ func fillAttributeViewKeyValues(attrView *av.AttributeView, collection av.Collec
} }
} }
func mergeKeyValues(kv1, kv2 []*av.KeyValues) (ret []*av.KeyValues) {
ret = kv2
for _, k1 := range kv1 {
found := false
for _, k2 := range kv2 {
if k1.Key.ID == k2.Key.ID {
found = true
break
}
}
if !found {
ret = append(ret, k1)
}
}
return
}
func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) { func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) {
value.Type = typ value.Type = typ
switch typ { switch typ {

View file

@ -19,7 +19,7 @@ import (
) )
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string, func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string,
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret *av.Gallery) { depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Gallery) {
ret = &av.Gallery{ ret = &av.Gallery{
BaseInstance: av.NewViewBaseInstance(view), BaseInstance: av.NewViewBaseInstance(view),
CoverFrom: view.Gallery.CoverFrom, CoverFrom: view.Gallery.CoverFrom,
@ -118,7 +118,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees) ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间 // 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews) fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了 // 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials) renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)

View file

@ -23,7 +23,7 @@ import (
) )
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string,
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret *av.Table) { depth *int, cachedAttrViews map[string]*av.AttributeView) (ret *av.Table) {
ret = &av.Table{ ret = &av.Table{
BaseInstance: av.NewViewBaseInstance(view), BaseInstance: av.NewViewBaseInstance(view),
Columns: []*av.TableColumn{}, Columns: []*av.TableColumn{},
@ -111,7 +111,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
ials := BatchGetBlockAttrs(ialIDs) ials := BatchGetBlockAttrs(ialIDs)
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间 // 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews) fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了 // 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials) renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)