From 4b8a22607a34a64585a307312c9a56f11bbd5ee3 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 21 Nov 2024 13:58:53 +0545 Subject: [PATCH] fix: dedup window for unsent notifications --- db/notifications.go | 4 +++- notification/events.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/db/notifications.go b/db/notifications.go index dc708d4a..1cb4f9e1 100644 --- a/db/notifications.go +++ b/db/notifications.go @@ -179,7 +179,9 @@ func GetMatchingNotificationSilences(ctx context.Context, resources models.Notif return silences, nil } -func SaveUnsentNotificationToHistory(ctx context.Context, sendHistory models.NotificationSendHistory, window time.Duration) error { +func SaveUnsentNotificationToHistory(ctx context.Context, sendHistory models.NotificationSendHistory) error { + window := ctx.Properties().Duration("notifications.dedup.window", time.Hour*24) + return ctx.DB().Exec("SELECT * FROM insert_unsent_notification_to_history(?, ?, ?, ?, ?)", sendHistory.NotificationID, sendHistory.SourceEvent, diff --git a/notification/events.go b/notification/events.go index 402b5db5..8c9f51cc 100644 --- a/notification/events.go +++ b/notification/events.go @@ -202,7 +202,7 @@ func addNotificationEvent(ctx context.Context, id string, celEnv map[string]any, SourceEvent: event.Name, Status: models.NotificationStatusSilenced, } - if err := db.SaveUnsentNotificationToHistory(ctx, history, ctx.Properties().Duration("notifications.dedup.window", time.Hour*24)); err != nil { + if err := db.SaveUnsentNotificationToHistory(ctx, history); err != nil { return fmt.Errorf("failed to save silenced notification history: %w", err) } @@ -220,7 +220,7 @@ func addNotificationEvent(ctx context.Context, id string, celEnv map[string]any, SourceEvent: event.Name, Status: models.NotificationStatusRepeatInterval, } - if err := db.SaveUnsentNotificationToHistory(ctx, history, time.Minute); err != nil { + if err := db.SaveUnsentNotificationToHistory(ctx, history); err != nil { return fmt.Errorf("failed to save silenced notification history: %w", err) }