pubsub: use concrete queries instead of an interface (#7686)

Remove the pubsub.Query interface and instead use the concrete query type.
Nothing uses any other implementation but pubsub/query.

* query: remove the error from the Matches method
* Update all usage.
This commit is contained in:
M. J. Fromberger
2022-01-25 11:16:48 -08:00
committed by GitHub
parent f163acf499
commit 079c7af007
10 changed files with 39 additions and 79 deletions
+10 -15
View File
@@ -67,13 +67,18 @@ func Compile(ast syntax.Query) (*Query, error) {
return &Query{ast: ast, conds: conds}, nil
}
// Matches satisfies part of the pubsub.Query interface. This implementation
// never reports an error. A nil *Query matches all events.
func (q *Query) Matches(events []types.Event) (bool, error) {
// Matches reports whether q matches the given events. If q == nil, the query
// matches any non-empty collection of events.
func (q *Query) Matches(events []types.Event) bool {
if q == nil {
return true, nil
return true
}
return q.matchesEvents(events), nil
for _, cond := range q.conds {
if !cond.matchesAny(events) {
return false
}
}
return len(events) != 0
}
// String matches part of the pubsub.Query interface.
@@ -92,16 +97,6 @@ func (q *Query) Syntax() syntax.Query {
return q.ast
}
// matchesEvents reports whether all the conditions match the given events.
func (q *Query) matchesEvents(events []types.Event) bool {
for _, cond := range q.conds {
if !cond.matchesAny(events) {
return false
}
}
return len(events) != 0
}
// A condition is a compiled match condition. A condition matches an event if
// the event has the designated type, contains an attribute with the given
// name, and the match function returns true for the attribute value.