MM-23547: remove redundant JSON parsing in push notifications (#14181)

Automatic Merge
This commit is contained in:
Agniva De Sarker 2020-04-08 21:08:57 +05:30 committed by GitHub
parent b8eb69281b
commit 583daeb132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 16 deletions

View file

@ -90,17 +90,6 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
)
}
notification, parseError := model.PushNotificationFromJson(strings.NewReader(msg.ToJson()))
if parseError != nil {
return model.NewAppError(
"pushNotification",
"api.push_notifications.message.parse.app_error",
nil,
parseError.Error(),
http.StatusInternalServerError,
)
}
for _, session := range sessions {
// Don't send notifications to this session if it's expired or we want to skip it
if session.IsExpired() || (skipSessionId != "" && skipSessionId == session.Id) {
@ -108,11 +97,11 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
}
// We made a copy to avoid decoding and parsing all the time
tmpMessage := notification
tmpMessage := msg.DeepCopy()
tmpMessage.SetDeviceIdAndPlatform(session.DeviceId)
tmpMessage.AckId = model.NewId()
err := a.sendToPushProxy(*tmpMessage, session)
err := a.sendToPushProxy(tmpMessage, session)
if err != nil {
a.NotificationsLog().Error("Notification error",
mlog.String("ackId", tmpMessage.AckId),
@ -123,7 +112,6 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
mlog.String("deviceId", tmpMessage.DeviceId),
mlog.String("status", err.Error()),
)
continue
}
@ -316,7 +304,7 @@ func (a *App) StopPushNotificationsHubWorkers() {
}
}
func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session) error {
func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Session) error {
msg.ServerId = a.DiagnosticId()
a.NotificationsLog().Info("Notification will be sent",

View file

@ -1350,7 +1350,7 @@ func TestAllPushNotifications(t *testing.T) {
}
// Run it with | grep -v '{"level"' to prevent spamming the console.
func BenchmarkPushNotification(b *testing.B) {
func BenchmarkPushNotificationThroughput(b *testing.B) {
th := SetupWithStoreMock(b)
defer th.TearDown()

View file

@ -74,6 +74,11 @@ func (me *PushNotification) ToJson() string {
return string(b)
}
func (me *PushNotification) DeepCopy() *PushNotification {
copy := *me
return &copy
}
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
index := strings.Index(deviceId, ":")