An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:zap: Improve database loading performance
Danielf69e776f8c8f
diff --git a/kernel/av/filter.go b/kernel/av/filter.goindex 3dac8c3f65..c75d6206f8 100644--- a/kernel/av/filter.go+++ b/kernel/av/filter.go@@ -79,7 +79,7 @@ const (FilterOperatorIsFalse FilterOperator = "Is false")-func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string) bool {+func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string, attrViewCache *map[string]*AttributeView) bool {if nil == filter || (nil == filter.Value && nil == filter.RelativeDate) {return true}@@ -117,7 +117,13 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID streturn false}- destAv, _ := ParseAttributeView(relKey.Relation.AvID)+ destAv := (*attrViewCache)[relKey.Relation.AvID]+ if nil == destAv {+ destAv, _ = ParseAttributeView(relKey.Relation.AvID)+ if nil != destAv {+ (*attrViewCache)[relKey.Relation.AvID] = destAv+ }+ }if nil == destAv {return false}diff --git a/kernel/av/table.go b/kernel/av/table.goindex 23c2b65973..adacb438b9 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -256,6 +256,8 @@ func (table *Table) FilterRows(attrView *AttributeView) {}rows := []*TableRow{}+ attrViewCache := map[string]*AttributeView{}+ attrViewCache[attrView.ID] = attrViewfor _, row := range table.Rows {pass := truefor j, index := range colIndexes {@@ -275,7 +277,7 @@ func (table *Table) FilterRows(attrView *AttributeView) {break}- if !row.Cells[index].Value.Filter(table.Filters[j], attrView, row.ID) {+ if !row.Cells[index].Value.Filter(table.Filters[j], attrView, row.ID, &attrViewCache) {pass = falsebreak}diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 55ab3306ad..538df4ae56 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -488,17 +488,20 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {return}+ attrViewCache := map[string]*av.AttributeView{}avIDs := strings.Split(avs, ",")for _, avID := range avIDs {- attrView, err := av.ParseAttributeView(avID)- if err != nil {- logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)- unbindBlockAv(nil, avID, blockID)- return+ attrView := attrViewCache[avID]+ if nil == attrView {+ attrView, _ = av.ParseAttributeView(avID)+ if nil == attrView {+ unbindBlockAv(nil, avID, blockID)+ return+ }+ attrViewCache[avID] = attrView}if 1 > len(attrView.Views) {- err = av.ErrViewNotFoundunbindBlockAv(nil, avID, blockID)return}@@ -568,9 +571,17 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {relVal := attrView.GetValue(kv.Key.Rollup.RelationKeyID, kv.Values[0].BlockID)if nil != relVal && nil != relVal.Relation {- destAv, _ := av.ParseAttributeView(relKey.Relation.AvID)+ destAv := attrViewCache[relKey.Relation.AvID]+ if nil == destAv {+ destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)+ if nil == destAv {+ break+ }+ attrViewCache[relKey.Relation.AvID] = destAv+ }+destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)- if nil != destAv && nil != destKey {+ if nil != destKey {for _, bID := range relVal.Relation.BlockIDs {destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)if nil == destVal {@@ -596,9 +607,14 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {break}- destAv, _ := av.ParseAttributeView(kv.Key.Relation.AvID)+ destAv := attrViewCache[kv.Key.Relation.AvID]if nil == destAv {- break+ destAv, _ = av.ParseAttributeView(kv.Key.Relation.AvID)+ if nil == destAv {+ break+ }++ attrViewCache[kv.Key.Relation.AvID] = destAv}blocks := map[string]*av.Value{}