From b745518c475060f223769665b787932642eae07b Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 13 Sep 2022 10:03:57 +0100 Subject: [PATCH] Linting fixes --- synapse/handlers/device.py | 4 +--- synapse/handlers/sync.py | 10 ++-------- synapse/storage/databases/main/cache.py | 4 +--- synapse/storage/databases/main/roommember.py | 16 +++++++--------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index fc54ef814f3c..8b2e932d28bf 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -271,9 +271,7 @@ async def get_user_ids_changed( possibly_left = possibly_changed | possibly_left # Double check if we still share rooms with the given user. - users_rooms = await self.store.get_rooms_for_users( - possibly_left - ) + users_rooms = await self.store.get_rooms_for_users(possibly_left) for changed_user_id, entries in users_rooms.items(): if any(room_id in room_ids for room_id in entries): possibly_left.discard(changed_user_id) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 80acd6930350..4e59596aa680 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -1474,9 +1474,7 @@ async def _generate_sync_entry_for_device_list( since_token.device_list_key ) if changed_users is not None: - result = await self.store.get_rooms_for_users( - changed_users - ) + result = await self.store.get_rooms_for_users(changed_users) for changed_user_id, entries in result.items(): # Check if the changed user shares any rooms with the user, @@ -1517,11 +1515,7 @@ async def _generate_sync_entry_for_device_list( newly_left_users.update(left_users) # Remove any users that we still share a room with. - left_users_rooms = ( - await self.store.get_rooms_for_users( - newly_left_users - ) - ) + left_users_rooms = await self.store.get_rooms_for_users(newly_left_users) for user_id, entries in left_users_rooms.items(): if any(rid in joined_rooms for rid in entries): newly_left_users.discard(user_id) diff --git a/synapse/storage/databases/main/cache.py b/synapse/storage/databases/main/cache.py index 7db2071fdaa2..7c9b72260c27 100644 --- a/synapse/storage/databases/main/cache.py +++ b/synapse/storage/databases/main/cache.py @@ -205,9 +205,7 @@ def _process_event_stream_row(self, token: int, row: EventsStreamRow) -> None: self.get_rooms_for_user_with_stream_ordering.invalidate( (data.state_key,) ) - self.get_rooms_for_user.invalidate( - (data.state_key,) - ) + self.get_rooms_for_user.invalidate((data.state_key,)) else: raise Exception("Unknown events stream row type %s" % (row.type,)) diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 7b14ada866a3..829543358178 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -617,15 +617,15 @@ def _get_users_server_still_shares_room_with_txn( ) @cached(max_entries=500000, iterable=True) - async def get_rooms_for_user( - self, user_id: str - ) -> FrozenSet[str]: + async def get_rooms_for_user(self, user_id: str) -> FrozenSet[str]: """Returns a set of room_ids the user is currently joined to. If a remote user only returns rooms this server is currently participating in. """ - rooms = self.get_rooms_for_user_with_stream_ordering.cache.get_immediate(user_id) + rooms = self.get_rooms_for_user_with_stream_ordering.cache.get_immediate( + user_id + ) if rooms: return frozenset(r.room_id for r in rooms) @@ -648,7 +648,7 @@ def _get_rooms_for_user_txn( """ txn.execute(sql, (user_id, Membership.JOIN)) - return frozenset(txn) + return frozenset(row[0] for row in txn) @cachedList( cached_method_name="get_rooms_for_user", @@ -656,7 +656,7 @@ def _get_rooms_for_user_txn( ) async def get_rooms_for_users( self, user_ids: Collection[str] - ) -> Dict[str, FrozenSet[GetRoomsForUserWithStreamOrdering]]: + ) -> Dict[str, FrozenSet[str]]: """A batched version of `get_rooms_for_user`. Returns: @@ -689,9 +689,7 @@ def _get_rooms_for_users_txn( txn.execute(sql, [Membership.JOIN] + args) - result: Dict[str, Set[str]] = { - user_id: set() for user_id in user_ids - } + result: Dict[str, Set[str]] = {user_id: set() for user_id in user_ids} for user_id, room_id in txn: result[user_id].add(room_id)