app: outdent skipSend condition (#14377)

We invert the skipSend condition and outdent the remaining block
to make the code a bit more idiomatic.

While here, we also change the dropping message level from info to
warn because that's what it should be.
Этот коммит содержится в:
Agniva De Sarker
2020-04-28 15:27:58 +05:30
коммит произвёл GitHub
родитель 6362926b5c
Коммит d3b36e3455

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

@@ -187,7 +187,7 @@ func (wc *WebConn) writePump() {
case model.WEBSOCKET_EVENT_TYPING, case model.WEBSOCKET_EVENT_TYPING,
model.WEBSOCKET_EVENT_STATUS_CHANGE, model.WEBSOCKET_EVENT_STATUS_CHANGE,
model.WEBSOCKET_EVENT_CHANNEL_VIEWED: model.WEBSOCKET_EVENT_CHANNEL_VIEWED:
mlog.Info( mlog.Warn(
"websocket.slow: dropping message", "websocket.slow: dropping message",
mlog.String("user_id", wc.UserId), mlog.String("user_id", wc.UserId),
mlog.String("type", msg.EventType()), mlog.String("type", msg.EventType()),
@@ -197,7 +197,10 @@ func (wc *WebConn) writePump() {
} }
} }
if !skipSend { if skipSend {
continue
}
var msgBytes []byte var msgBytes []byte
if evtOk { if evtOk {
cpyEvt := evt.SetSequence(wc.Sequence) cpyEvt := evt.SetSequence(wc.Sequence)
@@ -229,8 +232,6 @@ func (wc *WebConn) writePump() {
if wc.App.Metrics() != nil { if wc.App.Metrics() != nil {
wc.App.Metrics().IncrementWebSocketBroadcast(msg.EventType()) wc.App.Metrics().IncrementWebSocketBroadcast(msg.EventType())
} }
}
case <-ticker.C: case <-ticker.C:
wc.WebSocket.SetWriteDeadline(time.Now().Add(writeWaitTime)) wc.WebSocket.SetWriteDeadline(time.Now().Add(writeWaitTime))
if err := wc.WebSocket.WriteMessage(websocket.PingMessage, []byte{}); err != nil { if err := wc.WebSocket.WriteMessage(websocket.PingMessage, []byte{}); err != nil {