diff --git a/kernel/av/filter.go b/kernel/av/filter.go index df21ebc4c..3519cec3e 100644 --- a/kernel/av/filter.go +++ b/kernel/av/filter.go @@ -182,29 +182,20 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID st return false } - for _, blockID := range relVal.Relation.BlockIDs { - destVal := destAv.GetValue(key.Rollup.KeyID, blockID) - if nil == destVal { - if destAv.ExistItem(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值 - destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), key.Rollup.KeyID, blockID, destKey.Type) - } - if nil == destVal { - continue - } - } - + value.Rollup.BuildContents(destAv, destKey, relVal, key.Rollup.Calc, nil) + for _, content := range value.Rollup.Contents { switch filter.Operator { case FilterOperatorContains: - if destVal.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) { + if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) { return true } case FilterOperatorDoesNotContain: - ret := destVal.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) + ret := content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) if !ret { return false } default: - if destVal.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) { + if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) { return true } } diff --git a/kernel/av/value.go b/kernel/av/value.go index d4ff996ee..e3873556f 100644 --- a/kernel/av/value.go +++ b/kernel/av/value.go @@ -796,7 +796,34 @@ type ValueRollup struct { Contents []*Value `json:"contents"` } -func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) { +func (r *ValueRollup) BuildContents(destAv *AttributeView, destKey *Key, relationVal *Value, calc *RollupCalc, furtherCollection Collection) { + r.Contents = nil + for _, blockID := range relationVal.Relation.BlockIDs { + destVal := destAv.GetValue(destKey.ID, blockID) + if nil != furtherCollection && KeyTypeTemplate == destKey.Type { + destVal = furtherCollection.GetValue(blockID, destKey.ID) + } + + if nil == destVal { + if destAv.ExistItem(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值 + destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), destKey.ID, blockID, destKey.Type) + } + if nil == destVal { + continue + } + } + if KeyTypeNumber == destKey.Type { + destVal.Number.Format = destKey.NumberFormat + destVal.Number.FormatNumber() + } + + r.Contents = append(r.Contents, destVal.Clone()) + } + + r.calcContents(calc, destKey) +} + +func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) { if nil == calc { return } diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index aee199b98..b4c582a4b 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1534,29 +1534,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) { } } - kv.Values[0].Rollup.Contents = nil - for _, bID := range relVal.Relation.BlockIDs { - destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID) - if nil != furtherCollection && av.KeyTypeTemplate == destKey.Type { - destVal = furtherCollection.GetValue(bID, destKey.ID) - } - - if nil == destVal { - if destAv.ExistItem(bID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值 - destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type) - } - if nil == destVal { - continue - } - } - if av.KeyTypeNumber == destKey.Type { - destVal.Number.Format = destKey.NumberFormat - destVal.Number.FormatNumber() - } - - kv.Values[0].Rollup.Contents = append(kv.Values[0].Rollup.Contents, destVal.Clone()) - } - kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc, destKey) + kv.Values[0].Rollup.BuildContents(destAv, destKey, relVal, kv.Key.Rollup.Calc, furtherCollection) } } case av.KeyTypeRelation: diff --git a/kernel/sql/av.go b/kernel/sql/av.go index 16d381efc..fa8265da7 100644 --- a/kernel/sql/av.go +++ b/kernel/sql/av.go @@ -26,7 +26,6 @@ import ( "time" "github.com/88250/gulu" - "github.com/88250/lute/ast" "github.com/jinzhu/copier" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/av" @@ -385,7 +384,6 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection var furtherCollection av.Collection if av.KeyTypeTemplate == destKey.Type { - // 渲染目标视图,这样才能汇总渲染后的模板字段值 viewable := renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews) if nil != viewable { @@ -396,30 +394,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection } } - value.Rollup.Contents = nil - for _, blockID := range relVal.Relation.BlockIDs { - destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) - if nil != furtherCollection && av.KeyTypeTemplate == destKey.Type { - destVal = furtherCollection.GetValue(blockID, destKey.ID) - } - - if nil == destVal { - if destAv.ExistItem(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值 - destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) - } - if nil == destVal { - continue - } - } - if av.KeyTypeNumber == destKey.Type { - destVal.Number.Format = destKey.NumberFormat - destVal.Number.FormatNumber() - } - - value.Rollup.Contents = append(value.Rollup.Contents, destVal.Clone()) - } - - value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey) + value.Rollup.BuildContents(destAv, destKey, relVal, rollupKey.Rollup.Calc, furtherCollection) case av.KeyTypeRelation: // 渲染关联 value.Relation.Contents = nil relKey, _ := attrView.GetKey(value.KeyID)