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

Commit

Permalink
Refactor _on_new_room_event to reduce duplicate calls
Browse files Browse the repository at this point in the history
There is no point in repeatedly calling `on_new_event` with the same
`max_stream_token`.
  • Loading branch information
erikjohnston committed Sep 9, 2020
1 parent d283fcd commit 9b72316
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,30 +275,30 @@ def _notify_pending_new_room_events(self, max_room_stream_id: int):
"""
pending = self.pending_new_room_events
self.pending_new_room_events = []

users = set() # type: Set[Union[str, UserID]]
rooms = set() # type: Set[str]

for room_stream_id, event, extra_users in pending:
if room_stream_id > max_room_stream_id:
self.pending_new_room_events.append(
(room_stream_id, event, extra_users)
)
else:
self._on_new_room_event(event, max_room_stream_id, extra_users)

self._on_updated_room_token(max_room_stream_id)

def _on_new_room_event(
self,
event: EventBase,
max_room_stream_id: int,
extra_users: Collection[Union[str, UserID]] = [],
):
"""Notify any user streams that are interested in this room event"""

if event.type == EventTypes.Member and event.membership == Membership.JOIN:
self._user_joined_room(event.state_key, event.room_id)

self.on_new_event(
"room_key", max_room_stream_id, users=extra_users, rooms=[event.room_id]
)
if (
event.type == EventTypes.Member
and event.membership == Membership.JOIN
):
self._user_joined_room(event.state_key, event.room_id)

users.update(extra_users)
rooms.add(event.room_id)

if users or rooms:
self.on_new_event(
"room_key", max_room_stream_id, users=extra_users, rooms=[event.room_id]
)
self._on_updated_room_token(max_room_stream_id)

def _on_updated_room_token(self, max_room_stream_id: int):
"""Poke services that might care that the room position has been
Expand Down

0 comments on commit 9b72316

Please sign in to comment.