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

Skip unused calculations in sync handler #14908

Merged
merged 19 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ async def filter_room_account_data(
await self._room_filter.filter(events)
)

def blocks_all_rooms(self) -> bool:
return self._room_filter.filters_all_rooms()

DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
def blocks_all_presence(self) -> bool:
return (
self._presence_filter.filters_all_types()
Expand Down
19 changes: 18 additions & 1 deletion synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,7 @@ async def _generate_sync_entry_for_account_data(
since_token = sync_result_builder.since_token

if since_token and not sync_result_builder.full_state:
# TODO Do not fetch room account data if it will be unused.
(
global_account_data,
account_data_by_room,
Expand All @@ -1725,6 +1726,7 @@ async def _generate_sync_entry_for_account_data(
sync_config.user
)
else:
# TODO Do not fetch room account data if it will be unused.
(
global_account_data,
account_data_by_room,
Expand Down Expand Up @@ -1837,10 +1839,25 @@ async def _generate_sync_entry_for_rooms(

since_token = sync_result_builder.since_token

# If all rooms are blocked, we can skip bits of processing.
block_all_rooms = (
sync_result_builder.sync_config.filter_collection.blocks_all_rooms()
)

# 0. If there are no rooms to return *and* we don't care about presence
# or device list updates, there's nothing to do.
if (
block_all_rooms
and block_all_presence_data
and not include_device_list_updates
):
return set(), set(), set(), set()

DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
# 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
block_all_rooms
or since_token is None
and sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
clokep marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down