summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2021-12-07 12:33:13 +0000
committerDavid Robertson <davidr@element.io>2021-12-07 18:21:59 +0000
commitbca64f949e42bd5a45056da9bf8ece46dceae99b (patch)
treebf06772750f69e9743ef24aa9614fe7de996f07b
parentPull out `_classify_rooms_by_membership_changes` (diff)
downloadsynapse-bca64f949e42bd5a45056da9bf8ece46dceae99b.tar.xz
Remove unused branch
I claim that it is impossible to hit the `continue` which is removed in
this commit. Setup:

- `events` is a list of all membership events in the range
  `since < time <= now`.
- `non_joins` is the list of `e in events` with `e.membership` not equal
  to`"join"`.
- `events` is a nonempty list by construction of
  `mem_change_events_by_room_id`.

Rationale:

- We hit the deleted code only if `non_joins` is empty.
- If so, `events` consists only of `join` membership events.
- `events` is non_empty, so there was at least one join during the
  sync period.
- Therefore the room_id will belong to
  `sync_result_builder.joined_room_ids`. But this means we will have
 `continue`d in the branch above.
  - I'm assuming here that `joined_room_ids` and `events` are both using
   the same `now_token.room_key`.
-rw-r--r--synapse/handlers/sync.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index b62ec3416b..d8cbbb576d 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -1070,7 +1070,7 @@ class SyncHandler:
         At the end, we transfer data from the `sync_result_builder` to a new `SyncResult`
         instance to signify that the sync calculation is complete.
         """
-        # NB: The now_token gets changed by some of the generate_sync_* methods,
+        # NB: Parts of the now_token get changed by some of the generate_sync_* methods,
         # this is due to some of the underlying streams not supporting the ability
         # to query up to a given point.
         # Always use the `now_token` in `SyncResultBuilder`
@@ -1091,6 +1091,8 @@ class SyncHandler:
             # See https://github.com/matrix-org/matrix-doc/issues/1144
             raise NotImplementedError()
         else:
+            # The `room_key` part of the `now_token` is not changed by the sync
+            # machinery. If it did, `joined_room_ids` could become out of date.
             joined_room_ids = await self.get_rooms_for_user_at(
                 user_id, now_token.room_key
             )
@@ -1837,10 +1839,6 @@ class SyncHandler:
             if room_id in sync_result_builder.joined_room_ids:
                 continue
 
-            if not non_joins:
-                continue
-            last_non_join = non_joins[-1]
-
             # Check if we have left the room. This can either be because we were
             # joined before *or* that we since joined and then left.
             if events[-1].membership != Membership.JOIN:
@@ -1861,6 +1859,7 @@ class SyncHandler:
                         newly_left_rooms.append(room_id)
 
             # Only bother if we're still currently invited
+            last_non_join = non_joins[-1]
             should_invite = last_non_join.membership == Membership.INVITE
             if should_invite:
                 if last_non_join.sender not in ignored_users: