File size: 832 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
package message
import (
"sort"
"github.com/target/goalert/notification"
)
// dedupStatusMessages will remove old status updates if a newer one exists for the same alert/destination.
func dedupStatusMessages(messages []Message) ([]Message, []string) {
toProcess, result := splitPendingByType(messages, notification.MessageTypeAlertStatus)
sort.Slice(toProcess, func(i, j int) bool { return toProcess[i].AlertLogID > toProcess[j].AlertLogID })
type msgKey struct {
alertID int
dest notification.DestID
}
m := make(map[msgKey]struct{})
var toDelete []string
for _, msg := range toProcess {
key := msgKey{alertID: msg.AlertID, dest: msg.DestID}
if _, ok := m[key]; ok {
toDelete = append(toDelete, msg.ID)
continue
}
m[key] = struct{}{}
result = append(result, msg)
}
return result, toDelete
}
|