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

Commit 0d0783c

Browse files
author
David Robertson
committed
Always call old_mem_ev---exactly once.
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.
1 parent 6ff95ee commit 0d0783c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

synapse/handlers/sync.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,11 +1855,10 @@ async def _classify_rooms_by_membership_changes(
18551855
# User is in the room so we don't need to do the invite/leave checks
18561856
continue
18571857

1858+
old_mem_ev = await self._fetch_membership_event_at(
1859+
room_id, user_id, since_token
1860+
)
18581861
if room_id in sync_result_builder.joined_room_ids or has_join:
1859-
old_mem_ev = await self._fetch_membership_event_at(
1860-
room_id, user_id, since_token
1861-
)
1862-
18631862
# debug for #4422
18641863
if has_join and old_mem_ev is not None:
18651864
issue4422_logger.debug(
@@ -1883,9 +1882,6 @@ async def _classify_rooms_by_membership_changes(
18831882
if has_join:
18841883
newly_left_rooms.append(room_id)
18851884
else:
1886-
old_mem_ev = await self._fetch_membership_event_at(
1887-
room_id, user_id, since_token
1888-
)
18891885
if (
18901886
old_mem_ev is not None
18911887
and old_mem_ev.membership == Membership.JOIN

0 commit comments

Comments
 (0)