Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 26, 2021
1 parent bd1672d commit 7fe80a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
11 changes: 1 addition & 10 deletions bolt_transport.go
Expand Up @@ -257,16 +257,7 @@ func (t *BoltTransport) dispatchHistory(s *Subscriber, toSeq uint64) {
return fmt.Errorf("unable to unmarshal update: %w", err)
}

var disconnected bool
for _, t := range update.Topics {
if s.Match(t, update.Private) {
disconnected = !s.Dispatch(update, true)

break
}
}

if disconnected || (toSeq > 0 && binary.BigEndian.Uint64(k[:8]) >= toSeq) {
if (s.Match(update) && !s.Dispatch(update, true)) || (toSeq > 0 && binary.BigEndian.Uint64(k[:8]) >= toSeq) {
s.HistoryDispatched(responseLastEventID)

return nil
Expand Down
17 changes: 14 additions & 3 deletions subscriber.go
Expand Up @@ -152,8 +152,8 @@ func escapeTopics(topics []string) []string {
return escapedTopics
}

// Match checks if the current subscriber can access to the given topic.
func (s *Subscriber) Match(topic string, private bool) (match bool) {
// MatchTopic checks if the current subscriber can access to the given topic.
func (s *Subscriber) MatchTopic(topic string, private bool) (match bool) {
for i, ts := range s.Topics {
if ts == "*" || ts == topic {
match = true
Expand Down Expand Up @@ -190,11 +190,22 @@ func (s *Subscriber) Match(topic string, private bool) (match bool) {
return false
}

// Match checks if the current subscriber can receive the given update.
func (s *Subscriber) Match(u *Update) bool {
for _, t := range u.Topics {
if s.MatchTopic(t, u.Private) {
return true
}
}

return false
}

// getSubscriptions return the list of subscriptions associated to this subscriber.
func (s *Subscriber) getSubscriptions(topic, context string, active bool) []subscription {
var subscriptions []subscription //nolint:prealloc
for k, t := range s.Topics {
if topic != "" && !s.Match(topic, false) {
if topic != "" && !s.MatchTopic(topic, false) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion subscriber_list.go
Expand Up @@ -18,7 +18,7 @@ func NewSubscriberList(size int) *SubscriberList {
return false
}

return s.(*Subscriber).Match(p[1], p[0] == "p")
return s.(*Subscriber).MatchTopic(p[1], p[0] == "p")
}, size),
}
}
Expand Down

0 comments on commit 7fe80a6

Please sign in to comment.