diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2022-10-05 12:12:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 12:12:42 +0200 |
commit | 8c0c3441d88a612ca8e9ba4f83c6ff29ca73f5d0 (patch) | |
tree | 74b355bf97be6ad1b82cf89d16d564105f5373de /userapi/consumers | |
parent | ebd137cf6b2fbd767625dc5289b0bef6d1e51971 (diff) |
Add `RoomEventType` nats.Header to avoid unneeded unmarshalling (#2765)
Diffstat (limited to 'userapi/consumers')
-rw-r--r-- | userapi/consumers/roomserver.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/userapi/consumers/roomserver.go b/userapi/consumers/roomserver.go index 952de98f..a1287694 100644 --- a/userapi/consumers/roomserver.go +++ b/userapi/consumers/roomserver.go @@ -72,15 +72,16 @@ func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Msg) bool { msg := msgs[0] // Guaranteed to exist if onMessage is called + // Only handle events we care about + if rsapi.OutputType(msg.Header.Get(jetstream.RoomEventType)) != rsapi.OutputTypeNewRoomEvent { + return true + } var output rsapi.OutputEvent if err := json.Unmarshal(msg.Data, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("roomserver output log: message parse failure") return true } - if output.Type != rsapi.OutputTypeNewRoomEvent { - return true - } event := output.NewRoomEvent.Event if event == nil { log.Errorf("userapi consumer: expected event") |