Skip serializing /sync response if client has disconnected (#7927)

... it's a load of work which may be entirely redundant.
This commit is contained in:
Richard van der Hoff 2020-07-22 13:44:16 +01:00 committed by GitHub
parent b74919c72e
commit 923c995023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

1
changelog.d/7927.misc Normal file
View File

@ -0,0 +1 @@
Optimisation to /sync handling: skip serializing the response if the client has already disconnected.

View File

@ -178,6 +178,12 @@ class SyncRestServlet(RestServlet):
full_state=full_state, full_state=full_state,
) )
# the client may have disconnected by now; don't bother to serialize the
# response if so.
if request._disconnected:
logger.info("Client has disconnected; not serializing response.")
return 200, {}
time_now = self.clock.time_msec() time_now = self.clock.time_msec()
response_content = await self.encode_response( response_content = await self.encode_response(
time_now, sync_result, requester.access_token_id, filter_collection time_now, sync_result, requester.access_token_id, filter_collection