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

Commit

Permalink
Always call old_mem_ev---exactly once.
Browse files Browse the repository at this point in the history
I claim this is identical to the existing behaviour. Proof: consider the
boolean `room_id in sync_result_builder.joined_room_ids or has_join`.
If this is true, we make the first call to `_fetch_membership_event_at`.
Otherwise:

- `room_id not in sync_result_builder.joined_room_ids` and `not has_join`.
- The former means we continue on to inspect `events[-1].membership`.
- This is not `"join"`, or else `room_id in
  sync_result_builder.joined_room_ids` would be true.
- `has_join` is False, so we hit the `else` branch and make the second
  call to `_fetch_membership_event_at`.

So, assuming we continue beyond the first `continue`, we always call
fetch the old membership event exactly once. Do it up front to make the
reader's life easier.
  • Loading branch information
David Robertson committed Dec 7, 2021
1 parent 6ff95ee commit 0d0783c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,11 +1855,10 @@ async def _classify_rooms_by_membership_changes(
# User is in the room so we don't need to do the invite/leave checks
continue

old_mem_ev = await self._fetch_membership_event_at(
room_id, user_id, since_token
)
if room_id in sync_result_builder.joined_room_ids or has_join:
old_mem_ev = await self._fetch_membership_event_at(
room_id, user_id, since_token
)

# debug for #4422
if has_join and old_mem_ev is not None:
issue4422_logger.debug(
Expand All @@ -1883,9 +1882,6 @@ async def _classify_rooms_by_membership_changes(
if has_join:
newly_left_rooms.append(room_id)
else:
old_mem_ev = await self._fetch_membership_event_at(
room_id, user_id, since_token
)
if (
old_mem_ev is not None
and old_mem_ev.membership == Membership.JOIN
Expand Down

0 comments on commit 0d0783c

Please sign in to comment.