Skip to content
Snippets Groups Projects

Gofunc for notify, set toSend properly, fix unsent handling

2 files
+ 10
9
Compare changes
  • Side-by-side
  • Inline

Files

+ 9
8
@@ -188,16 +188,15 @@ func (nb *Impl) SendBatch(data map[int64][]*notifications.Data) ([]*notification
var ephemerals []int64
var unsent []*notifications.Data
for i, ilist := range data {
var overflow, trimmed []*notifications.Data
var overflow, toSend []*notifications.Data
if len(data) > nb.maxNotifications {
overflow = ilist[nb.maxNotifications:]
trimmed = ilist[:nb.maxNotifications]
toSend = ilist[:nb.maxNotifications]
} else {
toSend = ilist[:]
}
notifs, rest := notifications.BuildNotificationCSV(trimmed, nb.maxPayloadBytes-len([]byte(notificationsTag)))
for _, nd := range rest {
nb.Storage.GetNotificationBuffer().Add(id.Round(nd.RoundID), []*notifications.Data{nd})
}
notifs, rest := notifications.BuildNotificationCSV(toSend, nb.maxPayloadBytes-len([]byte(notificationsTag)))
overflow = append(overflow, rest...)
csvs[i] = string(notifs)
ephemerals = append(ephemerals, i)
@@ -207,8 +206,10 @@ func (nb *Impl) SendBatch(data map[int64][]*notifications.Data) ([]*notification
if err != nil {
return nil, errors.WithMessage(err, "Failed to get list of tokens to notify")
}
for _, n := range toNotify {
nb.notify(csvs[n.EphemeralId], n)
for i := range toNotify {
go func(res storage.GTNResult) {
nb.notify(csvs[res.EphemeralId], res)
}(toNotify[i])
}
return unsent, nil
}
Loading