Skip to content

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

:art: Improve av

Daniel50956851c804
diff --git a/kernel/sql/av.go b/kernel/sql/av.go
index f69a003e87..9746444003 100644
--- a/kernel/sql/av.go
+++ b/kernel/sql/av.go
@@ -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,
- depth *int, renderedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
- if 7 < *depth {
+ depth *int, cachedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
+ if 2 < *depth {
return
}
*depth++
switch view.LayoutType {
case av.LayoutTypeTable:
- ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews)
+ ret = RenderAttributeViewTable(attrView, view, query, depth, cachedAttrViews)
case av.LayoutTypeGallery:
- ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews)
+ ret = RenderAttributeViewGallery(attrView, view, query, depth, cachedAttrViews)
}
return
}
@@ -335,7 +335,7 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID 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() {
@@ -421,11 +421,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
break
}
- destAv := renderedAttrViews[relKey.Relation.AvID]
+ destAv := cachedAttrViews[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv {
- renderedAttrViews[relKey.Relation.AvID] = destAv
+ cachedAttrViews[relKey.Relation.AvID] = destAv
}
}
if nil == destAv {
@@ -440,7 +440,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
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, renderedAttrViews)
+ viewable := renderView(destAv, destAv.Views[0], "", depth, cachedAttrViews)
if nil != viewable {
furtherCollection = viewable.(av.Collection)
} else {
@@ -454,11 +454,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
value.Relation.Contents = nil
relKey, _ := attrView.GetKey(value.KeyID)
if nil != relKey && nil != relKey.Relation {
- destAv := renderedAttrViews[relKey.Relation.AvID]
+ destAv := cachedAttrViews[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv {
- renderedAttrViews[relKey.Relation.AvID] = destAv
+ cachedAttrViews[relKey.Relation.AvID] = destAv
}
}
if nil != destAv {
@@ -498,6 +498,10 @@ func fillAttributeViewTemplateValues(attrView *av.AttributeView, view *av.View,
for _, templateKey := range templateKeys {
for _, item := range collection.GetItems() {
value := item.GetValue(templateKey.ID)
+ if nil == value || nil == value.Template {
+ continue
+ }
+
keyValues := items[item.GetID()]
var ial map[string]string
blockVal := item.GetBlockValue()
@@ -550,6 +554,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) {
value.Type = typ
switch typ {
diff --git a/kernel/sql/av_gallery.go b/kernel/sql/av_gallery.go
index e81fc436f7..cda80a60bb 100644
--- a/kernel/sql/av_gallery.go
+++ b/kernel/sql/av_gallery.go
@@ -19,7 +19,7 @@ import (
)
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{
BaseInstance: av.NewViewBaseInstance(view),
CoverFrom: view.Gallery.CoverFrom,
@@ -118,7 +118,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
- fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews)
+ fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)
diff --git a/kernel/sql/av_table.go b/kernel/sql/av_table.go
index 60ae0acd3c..9940765727 100644
--- a/kernel/sql/av_table.go
+++ b/kernel/sql/av_table.go
@@ -23,7 +23,7 @@ import (
)
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{
BaseInstance: av.NewViewBaseInstance(view),
Columns: []*av.TableColumn{},
@@ -111,7 +111,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
ials := BatchGetBlockAttrs(ialIDs)
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
- fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews)
+ fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)