Skip to content

Commit

Permalink
cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Dec 14, 2023
1 parent 3250d41 commit 4574e2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 10 additions & 3 deletions database/redis/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,18 @@ func (connector *DbConnector) filterNotificationsByState(notifications []*moira.
toResave: make([]*moira.ScheduledNotification, 0, len(notifications)),
}

removedNotifications := make([]*moira.ScheduledNotification, 0, len(notifications))

triggerChecks, err := connector.getNotificationsTriggerChecks(notifications)
if err != nil {
return notificationTypes{}, fmt.Errorf("failed to get notifications trigger checks: %w", err)
}

for i, notification := range notifications {
if notification == nil {
continue
}

switch notification.GetState(triggerChecks[i]) {
case moira.ValidNotification:
types.valid = append(types.valid, notification)
Expand All @@ -229,16 +235,17 @@ func (connector *DbConnector) filterNotificationsByState(notifications []*moira.

case moira.RemovedNotification:
types.toRemove = append(types.toRemove, notification)
removedNotifications = append(removedNotifications, notification)
}
}

logToRemoveNotifications(connector.logger, types.toRemove)
logRemovedNotifications(connector.logger, removedNotifications)

return types, nil
}

// Helper function for logging information on to remove notifications
func logToRemoveNotifications(logger moira.Logger, toRemoveNotifications []*moira.ScheduledNotification) {
func logRemovedNotifications(logger moira.Logger, toRemoveNotifications []*moira.ScheduledNotification) {
if len(toRemoveNotifications) == 0 {
return
}
Expand Down Expand Up @@ -270,7 +277,7 @@ handleNotifications filters notifications into delayed and not delayed,
then filters delayed notifications by notification state, then merges the 2 arrays
of not delayed and valid delayed notifications into a single sorted array
Returns valid notifications in sorted order by timestamp and notifications to remove
Returns valid notifications in sorted order by timestamp, notifications to remove and to resave
*/
func (connector *DbConnector) handleNotifications(notifications []*moira.ScheduledNotification) (notificationTypes, error) {
if len(notifications) == 0 {
Expand Down
1 change: 0 additions & 1 deletion database/redis/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func TestFetchNotifications(t *testing.T) {
addNotifications(database, []moira.ScheduledNotification{notification, notificationNew, notificationOld})
actual, err := database.FetchNotifications(now+database.getDelayedTimeInSeconds(), 4) //nolint
So(err, ShouldBeNil)

So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification})

actual, total, err := database.GetNotifications(0, -1)
Expand Down

0 comments on commit 4574e2c

Please sign in to comment.