🐛 Incorrect results for database rollup field filtering https://github.com/siyuan-note/siyuan/issues/15608

This commit is contained in:
Daniel 2025-08-22 16:13:51 +08:00
parent 312be8a019
commit 61d0e5a3d6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 10 additions and 12 deletions

View file

@ -182,8 +182,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID st
return false return false
} }
value.Rollup.Contents = GetRollupContents(destAv, destKey, relVal.Relation.BlockIDs, nil) value.Rollup.BuildContents(destAv, destKey, relVal, key.Rollup.Calc, nil)
value.Rollup.RenderContents(key.Rollup.Calc, destKey)
for _, content := range value.Rollup.Contents { for _, content := range value.Rollup.Contents {
switch filter.Operator { switch filter.Operator {
case FilterOperatorContains: case FilterOperatorContains:

View file

@ -796,9 +796,9 @@ type ValueRollup struct {
Contents []*Value `json:"contents"` Contents []*Value `json:"contents"`
} }
func GetRollupContents(destAv *AttributeView, destKey *Key, relationBlockIDs []string, furtherCollection Collection) (ret []*Value) { func (r *ValueRollup) BuildContents(destAv *AttributeView, destKey *Key, relationVal *Value, calc *RollupCalc, furtherCollection Collection) {
ret = []*Value{} r.Contents = nil
for _, blockID := range relationBlockIDs { for _, blockID := range relationVal.Relation.BlockIDs {
destVal := destAv.GetValue(destKey.ID, blockID) destVal := destAv.GetValue(destKey.ID, blockID)
if nil != furtherCollection && KeyTypeTemplate == destKey.Type { if nil != furtherCollection && KeyTypeTemplate == destKey.Type {
destVal = furtherCollection.GetValue(blockID, destKey.ID) destVal = furtherCollection.GetValue(blockID, destKey.ID)
@ -817,12 +817,13 @@ func GetRollupContents(destAv *AttributeView, destKey *Key, relationBlockIDs []s
destVal.Number.FormatNumber() destVal.Number.FormatNumber()
} }
ret = append(ret, destVal.Clone()) r.Contents = append(r.Contents, destVal.Clone())
}
return
} }
func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) { r.calcContents(calc, destKey)
}
func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
if nil == calc { if nil == calc {
return return
} }

View file

@ -1534,8 +1534,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
} }
} }
kv.Values[0].Rollup.Contents = av.GetRollupContents(destAv, destKey, relVal.Relation.BlockIDs, furtherCollection) kv.Values[0].Rollup.BuildContents(destAv, destKey, relVal, kv.Key.Rollup.Calc, furtherCollection)
kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc, destKey)
} }
} }
case av.KeyTypeRelation: case av.KeyTypeRelation:

View file

@ -394,8 +394,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
} }
} }
value.Rollup.Contents = av.GetRollupContents(destAv, destKey, relVal.Relation.BlockIDs, furtherCollection) value.Rollup.BuildContents(destAv, destKey, relVal, rollupKey.Rollup.Calc, furtherCollection)
value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey)
case av.KeyTypeRelation: // 渲染关联 case av.KeyTypeRelation: // 渲染关联
value.Relation.Contents = nil value.Relation.Contents = nil
relKey, _ := attrView.GetKey(value.KeyID) relKey, _ := attrView.GetKey(value.KeyID)