Directly lookup local membership instead of getting all members in a room first (get_users_in_room mis-use) (#13608)

See https://github.com/matrix-org/synapse/pull/13575#discussion_r953023755
This commit is contained in:
Eric Eastwood 2022-08-24 14:13:12 -05:00 committed by GitHub
parent b93bd95e8a
commit d58615c82c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 17 deletions

View file

@ -534,6 +534,32 @@ class RoomMemberWorkerStore(EventsWorkerStore):
desc="get_local_users_in_room",
)
async def check_local_user_in_room(self, user_id: str, room_id: str) -> bool:
"""
Check whether a given local user is currently joined to the given room.
Returns:
A boolean indicating whether the user is currently joined to the room
Raises:
Exeption when called with a non-local user to this homeserver
"""
if not self.hs.is_mine_id(user_id):
raise Exception(
"Cannot call 'check_local_user_in_room' on "
"non-local user %s" % (user_id,),
)
(
membership,
member_event_id,
) = await self.get_local_current_membership_for_user_in_room(
user_id=user_id,
room_id=room_id,
)
return membership == Membership.JOIN
async def get_local_current_membership_for_user_in_room(
self, user_id: str, room_id: str
) -> Tuple[Optional[str], Optional[str]]: