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

Skip filtering during push if there are no push actions #13992

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog.d/13992.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up calculating push actions in large rooms.
5 changes: 5 additions & 0 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ async def action_for_event_by_user(
# Push rules say we should notify the user of this event
actions_by_user[uid] = actions

# If there aren't any actions then we can skip the rest of the
# processing.
if not actions_by_user:
return
Comment on lines +335 to +338
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally thinking that the change to filter_event_for_clients_with_state should be enough, but I guess this saves creating some objects and some awaits. So...I see no problem w/ it.


# This is a check for the case where user joins a room without being
# allowed to see history, and then the server receives a delayed event
# from before the user joined, which they should not be pushed for
Expand Down
4 changes: 4 additions & 0 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ async def filter_event_for_clients_with_state(
if event.internal_metadata.is_soft_failed():
return []

# Fast path if we don't have any user IDs to check.
if not user_ids:
return ()

# Make a set for all user IDs that haven't been filtered out by a check.
allowed_user_ids = set(user_ids)

Expand Down
4 changes: 2 additions & 2 deletions tests/rest/client/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def test_post_room_no_keys(self) -> None:
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
self.assertTrue("room_id" in channel.json_body)
assert channel.resource_usage is not None
self.assertEqual(35, channel.resource_usage.db_txn_count)
self.assertEqual(34, channel.resource_usage.db_txn_count)

def test_post_room_initial_state(self) -> None:
# POST with initial_state config key, expect new room id
Expand All @@ -723,7 +723,7 @@ def test_post_room_initial_state(self) -> None:
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
self.assertTrue("room_id" in channel.json_body)
assert channel.resource_usage is not None
self.assertEqual(38, channel.resource_usage.db_txn_count)
self.assertEqual(37, channel.resource_usage.db_txn_count)

def test_post_room_visibility_key(self) -> None:
# POST with visibility config key, expect new room id
Expand Down