From cf0f93860c6c8a06fb4dbe4e863160f3d3797506 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 8 Oct 2021 16:02:33 +0100 Subject: [PATCH] Group together the now_false cases Justification: - the only way to hit the final else branch is if `change is MatchChange.now_false` - if `not is_in_room`, then the `state_key` will be one of the `user_id in user_ids` and so we'll call `self._handle_remove_user` with the `state_key` and return early - therefore the call to `_handle_remove_user` in the final else branch was only hit if `is_in_room`, and so it can be moved to first `else` branch. Having made this change we now have three mutually exclusive cases (now_false, now_true, no_change). Therefore I can change if->elif for the no_change branch. --- synapse/handlers/user_directory.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py index e0b81becbc..d62d256f29 100644 --- a/synapse/handlers/user_directory.py +++ b/synapse/handlers/user_directory.py @@ -321,8 +321,8 @@ class UserDirectoryHandler(StateDeltasHandler): return else: logger.debug("Server is still in room: %r", room_id) - - if change is MatchChange.no_change: + await self._handle_remove_user(room_id, state_key) + elif change is MatchChange.no_change: # Handle any profile changes for remote users. # (For local users we are not forced to scan membership # events; instead the rest of the application calls @@ -342,8 +342,6 @@ class UserDirectoryHandler(StateDeltasHandler): state_key, event_id ) await self._track_user_joined_room(room_id, state_key) - else: # The user left - await self._handle_remove_user(room_id, state_key) async def _upsert_directory_entry_for_remote_user( self, user_id: str, event_id: str