Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Do not calculate presence or ephemeral events when they are filtered …
Browse files Browse the repository at this point in the history
…out (#14970)

This expands the previous optimisation from being only for initial
sync to being for all sync requests.

It also inverts some of the logic to be inclusive instead of exclusive.
  • Loading branch information
clokep committed Feb 2, 2023
1 parent 2186ebe commit f36da50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/14970.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of `/sync` in a few situations.
19 changes: 9 additions & 10 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,10 +1459,12 @@ async def generate_sync_result(
sync_result_builder, account_data_by_room
)

block_all_presence_data = (
since_token is None and sync_config.filter_collection.blocks_all_presence()
# Presence data is included if the server has it enabled and not filtered out.
include_presence_data = (
self.hs_config.server.use_presence
and not sync_config.filter_collection.blocks_all_presence()
)
if self.hs_config.server.use_presence and not block_all_presence_data:
if include_presence_data:
logger.debug("Fetching presence data")
await self._generate_sync_entry_for_presence(
sync_result_builder,
Expand Down Expand Up @@ -1841,15 +1843,12 @@ async def _generate_sync_entry_for_rooms(
"""

since_token = sync_result_builder.since_token

# 1. Start by fetching all ephemeral events in rooms we've joined (if required).
user_id = sync_result_builder.sync_config.user.to_string()
block_all_room_ephemeral = (
since_token is None
and sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
)

if block_all_room_ephemeral:
# 1. Start by fetching all ephemeral events in rooms we've joined (if required).
if (
sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
):
ephemeral_by_room: Dict[str, List[JsonDict]] = {}
else:
now_token, ephemeral_by_room = await self.ephemeral_by_room(
Expand Down

0 comments on commit f36da50

Please sign in to comment.