From 5892250cdf96bb862a5a9d9b15bfa1cb61736d38 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 9 Aug 2022 20:52:15 +0200 Subject: [PATCH] Properly convert Constraints on record filter --- compose/types/record.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/compose/types/record.go b/compose/types/record.go index 520cd0cb9..718bb85fa 100644 --- a/compose/types/record.go +++ b/compose/types/record.go @@ -109,10 +109,19 @@ const ( recordFieldNamespaceID = "namespaceID" ) -// ToFilter wraps RecordFilter with struct that -// implements filter.Filter interface -func (f RecordFilter) ToFilter() filter.Filter { - c := make(map[string][]any) +func (f RecordFilter) ToConstraintedFilter(c map[string][]any) filter.Filter { + return &recordFilter{ + RecordFilter: f, + constraints: c, + } +} + +func (f recordFilter) Constraints() map[string][]any { + c := f.constraints + + if c == nil { + c = make(map[string][]any) + } for _, id := range f.LabeledIDs { c[recordFieldID] = append(c[recordFieldID], id) @@ -126,18 +135,7 @@ func (f RecordFilter) ToFilter() filter.Filter { c[recordFieldNamespaceID] = []any{f.NamespaceID} } - return f.ToConstraintedFilter(c) -} - -func (f RecordFilter) ToConstraintedFilter(c map[string][]any) filter.Filter { - return &recordFilter{ - RecordFilter: f, - constraints: c, - } -} - -func (f recordFilter) Constraints() map[string][]any { - return f.constraints + return c } func (f recordFilter) Expression() string { return f.Query }