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

Commit 0f63c73

Browse files
clokepDavid Robertson
authored andcommitted
Do not calculate presence or ephemeral events when they are filtered 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.
1 parent c9564e0 commit 0f63c73

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

changelog.d/14970.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve performance of `/sync` in a few situations.

synapse/handlers/sync.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,10 +1459,12 @@ async def generate_sync_result(
14591459
sync_result_builder, account_data_by_room
14601460
)
14611461

1462-
block_all_presence_data = (
1463-
since_token is None and sync_config.filter_collection.blocks_all_presence()
1462+
# Presence data is included if the server has it enabled and not filtered out.
1463+
include_presence_data = (
1464+
self.hs_config.server.use_presence
1465+
and not sync_config.filter_collection.blocks_all_presence()
14641466
)
1465-
if self.hs_config.server.use_presence and not block_all_presence_data:
1467+
if include_presence_data:
14661468
logger.debug("Fetching presence data")
14671469
await self._generate_sync_entry_for_presence(
14681470
sync_result_builder,
@@ -1841,15 +1843,12 @@ async def _generate_sync_entry_for_rooms(
18411843
"""
18421844

18431845
since_token = sync_result_builder.since_token
1844-
1845-
# 1. Start by fetching all ephemeral events in rooms we've joined (if required).
18461846
user_id = sync_result_builder.sync_config.user.to_string()
1847-
block_all_room_ephemeral = (
1848-
since_token is None
1849-
and sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
1850-
)
18511847

1852-
if block_all_room_ephemeral:
1848+
# 1. Start by fetching all ephemeral events in rooms we've joined (if required).
1849+
if (
1850+
sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
1851+
):
18531852
ephemeral_by_room: Dict[str, List[JsonDict]] = {}
18541853
else:
18551854
now_token, ephemeral_by_room = await self.ephemeral_by_room(

0 commit comments

Comments
 (0)