From 3c92154563c2e549fbdd1b093fc6a582ef05222e Mon Sep 17 00:00:00 2001 From: almostinf Date: Tue, 7 Nov 2023 16:48:25 +0300 Subject: [PATCH] fix removed notification logs --- database/redis/notification.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/database/redis/notification.go b/database/redis/notification.go index d0779f2fd..d52ba2816 100644 --- a/database/redis/notification.go +++ b/database/redis/notification.go @@ -377,15 +377,24 @@ func getLimitedNotifications( // Helper function for logging information on removed notifications func logRemovedNotifications(logger moira.Logger, removedNotifications []*moira.ScheduledNotification) { - removedNotificationsTriggerIDs := make([]string, 0, len(removedNotifications)) + triggerIDsSet := make(map[string]struct{}, len(removedNotifications)) for _, removedNotification := range removedNotifications { - if removedNotification != nil { - removedNotificationsTriggerIDs = append(removedNotificationsTriggerIDs, removedNotification.Trigger.ID) + if removedNotification == nil { + continue + } + + if _, ok := triggerIDsSet[removedNotification.Trigger.ID]; !ok { + triggerIDsSet[removedNotification.Trigger.ID] = struct{}{} } } + triggerIDs := make([]string, 0, len(triggerIDsSet)) + for triggerID := range triggerIDsSet { + triggerIDs = append(triggerIDs, triggerID) + } + logger.Info(). - Interface("removed_notifications_trigger_ids", removedNotificationsTriggerIDs). + Interface("notification_trigger_ids", triggerIDs). Int("removed_count", len(removedNotifications)). Msg("Remove notifications in transaction") }