diff --git a/notifications/notifications.go b/notifications/notifications.go index 9466ea6efdc10056ce893d55e3731977b8c232a4..94c83290d569c6ac3c5525a05c3cd698df21c8fa 100644 --- a/notifications/notifications.go +++ b/notifications/notifications.go @@ -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 } diff --git a/storage/database.go b/storage/database.go index 117f7bc25737c4e8f83aa8cc1934d35eb2f07fa4..5406c42a3e4df2bb9358773171f82f06aa7b196d 100644 --- a/storage/database.go +++ b/storage/database.go @@ -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 {