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

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2020-04-08 21:08:57 +05:30
коммит произвёл GitHub
родитель b8eb69281b
Коммит 583daeb132
3 изменённых файлов: 9 добавлений и 16 удалений

Просмотреть файл

@@ -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 { for _, session := range sessions {
// Don't send notifications to this session if it's expired or we want to skip it // Don't send notifications to this session if it's expired or we want to skip it
if session.IsExpired() || (skipSessionId != "" && skipSessionId == session.Id) { 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 // We made a copy to avoid decoding and parsing all the time
tmpMessage := notification tmpMessage := msg.DeepCopy()
tmpMessage.SetDeviceIdAndPlatform(session.DeviceId) tmpMessage.SetDeviceIdAndPlatform(session.DeviceId)
tmpMessage.AckId = model.NewId() tmpMessage.AckId = model.NewId()
err := a.sendToPushProxy(*tmpMessage, session) err := a.sendToPushProxy(tmpMessage, session)
if err != nil { if err != nil {
a.NotificationsLog().Error("Notification error", a.NotificationsLog().Error("Notification error",
mlog.String("ackId", tmpMessage.AckId), mlog.String("ackId", tmpMessage.AckId),
@@ -123,7 +112,6 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
mlog.String("deviceId", tmpMessage.DeviceId), mlog.String("deviceId", tmpMessage.DeviceId),
mlog.String("status", err.Error()), mlog.String("status", err.Error()),
) )
continue 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() msg.ServerId = a.DiagnosticId()
a.NotificationsLog().Info("Notification will be sent", a.NotificationsLog().Info("Notification will be sent",

Просмотреть файл

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

Просмотреть файл

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