[perf] WebsocketLoadBalancer: check is_restricted_message once

...and filter clients early on.
This commit is contained in:
Jakob Ackermann 2020-02-24 14:39:34 +01:00 committed by Jakob Ackermann
parent 5282f8f531
commit a70c1e1fa2

View file

@ -77,8 +77,15 @@ module.exports = WebsocketLoadBalancer =
status = EventLogger.checkEventOrder("editor-events", message._id, message) status = EventLogger.checkEventOrder("editor-events", message._id, message)
if status is "duplicate" if status is "duplicate"
return # skip duplicate events return # skip duplicate events
is_restricted_message = message.message not in RESTRICTED_USER_MESSAGE_TYPE_PASS_LIST
# send messages only to unique clients (due to duplicate entries in io.sockets.clients) # send messages only to unique clients (due to duplicate entries in io.sockets.clients)
clientList = io.sockets.clients(message.room_id) clientList = io.sockets.clients(message.room_id)
.filter((client) ->
!(is_restricted_message && client.ol_context['is_restricted_user'])
)
# avoid unnecessary work if no clients are connected # avoid unnecessary work if no clients are connected
return if clientList.length is 0 return if clientList.length is 0
logger.log { logger.log {
@ -93,11 +100,9 @@ module.exports = WebsocketLoadBalancer =
Async.eachLimit clientList Async.eachLimit clientList
, 2 , 2
, (client, cb) -> , (client, cb) ->
is_restricted_user = client.ol_context['is_restricted_user']
if !seen[client.id] if !seen[client.id]
seen[client.id] = true seen[client.id] = true
if !(is_restricted_user && message.message not in RESTRICTED_USER_MESSAGE_TYPE_PASS_LIST) client.emit(message.message, message.payload...)
client.emit(message.message, message.payload...)
cb() cb()
, (err) -> , (err) ->
if err? if err?