From 056a8ace2b1a009fb1d08059278c82b944af5ab9 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 7 Feb 2024 10:14:51 +0000 Subject: [PATCH 1/2] stop using pointers for subscriber --- domain/events.go | 2 +- feeds/combiner.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/domain/events.go b/domain/events.go index d82aa958..af6577c8 100644 --- a/domain/events.go +++ b/domain/events.go @@ -289,7 +289,7 @@ type AlertEvent struct { Event *protocol.AlertEvent Logs []LogEntry Timestamps *TrackingTimestamps - Subscriber *Subscriber + Subscriber Subscriber } // ToMessage converts the AlertEvent to the protocol.TransactionEvent message diff --git a/feeds/combiner.go b/feeds/combiner.go index f6db4f5d..2ba0f0b9 100644 --- a/feeds/combiner.go +++ b/feeds/combiner.go @@ -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 From 265e2840b97b58fd7e966231118f2cb4adb131f3 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 7 Feb 2024 10:16:18 +0000 Subject: [PATCH 2/2] adjust combiner cache --- feeds/combiner.go | 6 +++--- feeds/combiner_cache.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/feeds/combiner.go b/feeds/combiner.go index 2ba0f0b9..6ea2167c 100644 --- a/feeds/combiner.go +++ b/feeds/combiner.go @@ -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) } } @@ -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 { @@ -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 diff --git a/feeds/combiner_cache.go b/feeds/combiner_cache.go index efc79b3d..e28672d7 100644 --- a/feeds/combiner_cache.go +++ b/feeds/combiner_cache.go @@ -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) }