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

Only notify the target of a membership event #14971

Merged
merged 3 commits into from
Feb 6, 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
1 change: 1 addition & 0 deletions changelog.d/14971.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of joining and leaving large rooms with many local users.
29 changes: 20 additions & 9 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,26 @@ async def _get_rules_for_event(
Returns:
Mapping of user ID to their push rules.
"""
# We get the users who may need to be notified by first fetching the
# local users currently in the room, finding those that have push rules,
# and *then* checking which users are actually allowed to see the event.
#
# The alternative is to first fetch all users that were joined at the
# event, but that requires fetching the full state at the event, which
# may be expensive for large rooms with few local users.

local_users = await self.store.get_local_users_in_room(event.room_id)
# If this is a membership event, only calculate push rules for the target.
# While it's possible for users to configure push rules to respond to such an
# event, in practise nobody does this. At the cost of violating the spec a
# little, we can skip fetching a huge number of push rules in large rooms.
# This helps make joins and leaves faster.
if event.type == EventTypes.Member:
if self.hs.is_mine_id(event.state_key):
local_users = [event.state_key]
else:
return {}
else:
# We get the users who may need to be notified by first fetching the
# local users currently in the room, finding those that have push rules,
# and *then* checking which users are actually allowed to see the event.
#
# The alternative is to first fetch all users that were joined at the
# event, but that requires fetching the full state at the event, which
# may be expensive for large rooms with few local users.

local_users = await self.store.get_local_users_in_room(event.room_id)

# Filter out appservice users.
local_users = [
Expand Down