Improve database loading performance

This commit is contained in:
Daniel 2024-10-20 10:35:49 +08:00
parent 2011ab84e5
commit f69e776f8c
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 37 additions and 13 deletions

View file

@ -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 st
return 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
}

View file

@ -256,6 +256,8 @@ func (table *Table) FilterRows(attrView *AttributeView) {
}
rows := []*TableRow{}
attrViewCache := map[string]*AttributeView{}
attrViewCache[attrView.ID] = attrView
for _, row := range table.Rows {
pass := true
for 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 = false
break
}