Skip to content
Snippets Groups Projects
Commit b719e64d authored by Jonah Husson's avatar Jonah Husson
Browse files

Merge branch 'hotfix/notification-list' into 'release'

Gofunc for notify, set toSend properly, fix unsent handling

See merge request elixxir/notifications-bot!27
parents 5a79c512 7bb3878f
Branches
Tags
2 merge requests!32Release,!27Gofunc for notify, set toSend properly, fix unsent handling
......@@ -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
}
......
......@@ -138,7 +138,7 @@ func newDatabase(username, password, dbName, address,
// Initialize the database schema
// WARNING: Order is important. Do not change without database testing
models := []interface{}{&User{}, &Ephemeral{}}
models := []interface{}{&User{}, &Ephemeral{}, &State{}}
for _, model := range models {
err = db.AutoMigrate(model)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment