From 632ee7582ddac81a5ee91309fe5c3dfd33c439e4 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Thu, 12 May 2022 09:27:47 +0200 Subject: [PATCH] some fixes --- synapse/handlers/sync.py | 6 +++--- synapse/storage/databases/main/metrics.py | 4 ++-- synapse/storage/databases/main/push_rule.py | 4 ++-- synapse/storage/databases/main/roommember.py | 16 +++++++--------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 2c555a66d066..5d8437aa78bb 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -410,11 +410,11 @@ async def current_sync_for_user( set_tag(SynapseTags.SYNC_RESULT, bool(sync_result)) return sync_result - async def push_rules_for_user(self, user: UserID) -> JsonDict: + async def push_rules_for_user(self, user: UserID) -> Dict[str, Dict[str, list]]: user_id = user.to_string() rules = await self.store.get_push_rules_for_user(user_id) - rules = format_push_rules_for_user(user, rules) - return rules + result = format_push_rules_for_user(user, rules) + return result async def ephemeral_by_room( self, diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py index 4f3cb1f5e9fc..f3eed03567bb 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -133,7 +133,7 @@ def _count_messages(txn: LoggingTransaction) -> int: """ txn.execute(sql, (like_clause, self.stream_ordering_day_ago)) - (count,) = txn.fetchone() + (count,) = cast(Tuple[int], txn.fetchone()) return count return await self.db_pool.runInteraction( @@ -189,7 +189,7 @@ def _count_messages(txn: LoggingTransaction) -> int: """ txn.execute(sql, (like_clause, self.stream_ordering_day_ago)) - (count,) = txn.fetchone() + (count,) = cast(Tuple[int], txn.fetchone()) return count return await self.db_pool.runInteraction( diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index cfa809278f74..b9262f8d2e7a 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -199,7 +199,7 @@ def have_push_rules_changed_txn(txn: LoggingTransaction) -> bool: " WHERE user_id = ? AND ? < stream_id" ) txn.execute(sql, (user_id, last_id)) - (count,) = txn.fetchone() + (count,) = cast(Tuple[int], txn.fetchone()) return bool(count) return await self.db_pool.runInteraction( @@ -345,7 +345,7 @@ async def get_all_push_rule_updates( return [], current_id, False def get_all_push_rule_updates_txn( - txn: LoggingTransaction + txn: LoggingTransaction, ) -> Tuple[List[Tuple[int, tuple]], int, bool]: sql = """ SELECT stream_id, user_id diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 551df44659e8..c6d3a2e18d80 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -51,7 +51,7 @@ ProfileInfo, RoomsForUser, ) -from synapse.types import JsonDict, PersistedEventPosition, StateMap, get_domain_from_id +from synapse.types import PersistedEventPosition, StateMap, get_domain_from_id from synapse.util.async_helpers import Linearizer from synapse.util.caches import intern_string from synapse.util.caches.descriptors import _CacheContext, cached, cachedList @@ -189,9 +189,7 @@ async def get_users_in_room(self, room_id: str) -> List[str]: "get_users_in_room", self.get_users_in_room_txn, room_id ) - def get_users_in_room_txn( - self, txn: LoggingTransaction, room_id: str - ) -> List[str]: + def get_users_in_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[str]: # If we can assume current_state_events.membership is up to date # then we can avoid a join, which is a Very Good Thing given how # frequently this function gets called. @@ -232,7 +230,7 @@ async def get_users_in_room_with_profiles( """ def _get_users_in_room_with_profiles( - txn: LoggingTransaction + txn: LoggingTransaction, ) -> Dict[str, ProfileInfo]: sql = """ SELECT state_key, display_name, avatar_url FROM room_memberships as m @@ -672,7 +670,7 @@ async def get_users_who_share_room_with_user( async def get_joined_users_from_context( self, event: EventBase, context: EventContext ) -> Dict[str, ProfileInfo]: - state_group: Union[object, Optional[int]] = context.state_group + state_group = context.state_group if not state_group: # If state_group is None it means it has yet to be assigned a # state group, i.e. we need to make sure that calls with a state_group @@ -1271,9 +1269,9 @@ def _background_current_state_membership_txn( class RoomMemberStore( - RoomMemberWorkerStore, - RoomMemberBackgroundUpdateStore, - CacheInvalidationWorkerStore, + RoomMemberWorkerStore, + RoomMemberBackgroundUpdateStore, + CacheInvalidationWorkerStore, ): def __init__( self,