satellite/nodeevents: deduplicate node IDs

Remove dupulicate node IDs when sending notifications.

Change-Id: I76c642e342081f8fdf8248443de8383b9e88eed2
This commit is contained in:
Cameron 2023-02-03 17:11:31 -05:00 committed by Storj Robot
parent f733cb255b
commit 38275bd710
2 changed files with 12 additions and 2 deletions

View File

@ -69,8 +69,13 @@ func (c *CustomerioNotifier) Notify(ctx context.Context, satellite string, event
}
var nodeIDs string
idsMap := make(map[string]struct{})
for _, e := range events {
nodeIDs = nodeIDs + e.NodeID.String() + ","
idStr := e.NodeID.String()
if _, ok := idsMap[idStr]; !ok {
idsMap[idStr] = struct{}{}
nodeIDs = nodeIDs + idStr + ","
}
}
nodeIDs = strings.TrimSuffix(nodeIDs, ",")

View File

@ -28,8 +28,13 @@ func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []No
if len(events) == 0 {
return nil
}
idsMap := make(map[string]struct{})
for _, e := range events {
nodeIDs = nodeIDs + e.NodeID.String() + ","
idStr := e.NodeID.String()
if _, ok := idsMap[idStr]; !ok {
idsMap[idStr] = struct{}{}
nodeIDs = nodeIDs + idStr + ","
}
}
nodeIDs = strings.TrimSuffix(nodeIDs, ",")