mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-26 00:33:23 -04:00
MM-23547: remove redundant JSON parsing in push notifications (#14181)
Automatic Merge
This commit is contained in:
parent
b8eb69281b
commit
583daeb132
3 changed files with 9 additions and 16 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,11 @@ func (me *PushNotification) ToJson() string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
func (me *PushNotification) DeepCopy() *PushNotification {
|
||||
copy := *me
|
||||
return ©
|
||||
}
|
||||
|
||||
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
|
||||
|
||||
index := strings.Index(deviceId, ":")
|
||||
|
|
|
|||
Loading…
Reference in a new issue