Skip to content

Commit

Permalink
Remove unnecessary filter accumulation logic
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 committed Sep 29, 2023
1 parent 6915382 commit 18d0553
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 28 deletions.
26 changes: 0 additions & 26 deletions pkg/eventfilter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@ const (
// FilterResult has the result of the filtering operation.
type FilterResult string

func (x FilterResult) And(y FilterResult) FilterResult {
if x == NoFilter {
return y
}
if y == NoFilter {
return x
}
if x == PassFilter && y == PassFilter {
return PassFilter
}
return FailFilter
}

func (x FilterResult) Or(y FilterResult) FilterResult {
if x == NoFilter {
return y
}
if y == NoFilter {
return x
}
if x == PassFilter || y == PassFilter {
return PassFilter
}
return FailFilter
}

// Filter is an interface representing an event filter of the trigger filter
type Filter interface {
// Filter compute the predicate on the provided event and returns the result of the matching
Expand Down
2 changes: 1 addition & 1 deletion pkg/eventfilter/subscriptionsapi/all_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (filter *allFilter) Filter(ctx context.Context, event cloudevents.Event) ev
filter.rwMutex.RLock()
defer filter.rwMutex.RUnlock()
for i, f := range filter.filters {
res = res.And(f.filter.Filter(ctx, event))
res = f.filter.Filter(ctx, event)
// Short circuit to optimize it
if res == eventfilter.FailFilter {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/eventfilter/subscriptionsapi/any_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (filter *anyFilter) Filter(ctx context.Context, event cloudevents.Event) ev
filter.rwMutex.RLock()
defer filter.rwMutex.RUnlock()
for i, f := range filter.filters {
res = res.Or(f.filter.Filter(ctx, event))
res = f.filter.Filter(ctx, event)
// Short circuit to optimize it
if res == eventfilter.PassFilter {
select {
Expand Down

0 comments on commit 18d0553

Please sign in to comment.