satellite/nodeevents: minor changes to dedupe node IDs

`idsMap` renamed to `seen`. The map key is now storj.NodeID rather than
string.

Change-Id: Ia120d21c94eeecd1b855910bf27123dcd1dc7f97
This commit is contained in:
Cameron 2023-02-09 10:42:49 -05:00 committed by Storj Robot
parent 491fa78840
commit ce23ce0dc9
2 changed files with 12 additions and 10 deletions

View File

@ -13,6 +13,8 @@ import (
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/common/storj"
)
// CustomerioConfig handles customer.io credentials info.
@ -69,12 +71,11 @@ func (c *CustomerioNotifier) Notify(ctx context.Context, satellite string, event
}
var nodeIDs string
idsMap := make(map[string]struct{})
seen := make(map[storj.NodeID]struct{})
for _, e := range events {
idStr := e.NodeID.String()
if _, ok := idsMap[idStr]; !ok {
idsMap[idStr] = struct{}{}
nodeIDs = nodeIDs + idStr + ","
if _, ok := seen[e.NodeID]; !ok {
seen[e.NodeID] = struct{}{}
nodeIDs = nodeIDs + e.NodeID.String() + ","
}
}
nodeIDs = strings.TrimSuffix(nodeIDs, ",")

View File

@ -8,6 +8,8 @@ import (
"strings"
"go.uber.org/zap"
"storj.io/common/storj"
)
// MockNotifier implements the Notifier interface.
@ -28,12 +30,11 @@ func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []No
if len(events) == 0 {
return nil
}
idsMap := make(map[string]struct{})
seen := make(map[storj.NodeID]struct{})
for _, e := range events {
idStr := e.NodeID.String()
if _, ok := idsMap[idStr]; !ok {
idsMap[idStr] = struct{}{}
nodeIDs = nodeIDs + idStr + ","
if _, ok := seen[e.NodeID]; !ok {
seen[e.NodeID] = struct{}{}
nodeIDs = nodeIDs + e.NodeID.String() + ","
}
}
nodeIDs = strings.TrimSuffix(nodeIDs, ",")