Skip to content

Commit

Permalink
adjust combiner cache
Browse files Browse the repository at this point in the history
  • Loading branch information
aomerk authored and dkeysil committed Mar 5, 2024
1 parent 056a8ac commit 265e284
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions feeds/combiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (cf *combinerFeed) handleSubscriptions(alertHandlers []cfHandler, subscript
break
}
}
cf.processAlerts(cf.ctx, logger, &subscriber, subscriberAlerts, alertHandlers)
cf.processAlerts(cf.ctx, logger, subscriber, subscriberAlerts, alertHandlers)
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ func subscriptionsToAlertInputs(subscriptions []*protocol.CombinerBotSubscriptio
// the remaining alerts to the alert handlers passed in as an argument.
// It uses a cache to prevent duplicate processing of alerts and creates an AlertEvent object to pass to each alert handler.
// It is thread-safe as it acquires a lock on the combinerCache mutex before accessing or modifying it.
func (cf *combinerFeed) processAlerts(_ context.Context, logger *log.Entry, subscriber *domain.Subscriber,
func (cf *combinerFeed) processAlerts(_ context.Context, logger *log.Entry, subscriber domain.Subscriber,
alerts []*protocol.AlertEvent,
alertHandlers []cfHandler) {
for _, alert := range alerts {
Expand Down Expand Up @@ -326,7 +326,7 @@ func (cf *combinerFeed) processAlerts(_ context.Context, logger *log.Entry, subs
Feed: time.Now().UTC(),
SourceAlert: alertCA,
},
Subscriber: *subscriber,
Subscriber: subscriber,
}

// call each alert handler with the AlertEvent object
Expand Down
4 changes: 2 additions & 2 deletions feeds/combiner_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func newCombinerCache(path string) (*combinerCache, error) {
return &combinerCache{cache: alertCache, path: path}, nil
}

func (c *combinerCache) Exists(subscriber *domain.Subscriber, alert *protocol.AlertEvent) bool {
func (c *combinerCache) Exists(subscriber domain.Subscriber, alert *protocol.AlertEvent) bool {
_, exists := c.cache.Get(encodeAlertCacheKey(subscriber.BotID, subscriber.BotImage, alert.Alert.Hash))
return exists
}

func (c *combinerCache) Set(subscriber *domain.Subscriber, alert *protocol.AlertEvent) {
func (c *combinerCache) Set(subscriber domain.Subscriber, alert *protocol.AlertEvent) {
c.cache.Set(encodeAlertCacheKey(subscriber.BotID, subscriber.BotImage, alert.Alert.Hash), struct{}{}, cache.DefaultExpiration)
}

Expand Down

0 comments on commit 265e284

Please sign in to comment.