Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Use simple_select_onecol in get_rooms_for_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Sep 28, 2022
1 parent 21c8e8d commit 9907aaa
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,26 +649,18 @@ async def get_rooms_for_user(self, user_id: str) -> FrozenSet[str]:
if rooms:
return frozenset(r.room_id for r in rooms)

return await self.db_pool.runInteraction(
"get_rooms_for_user",
self._get_rooms_for_user_txn,
user_id,
room_ids = await self.db_pool.simple_select_onecol(
table="current_state_events",
keyvalues={
"type": EventTypes.Member,
"membership": Membership.JOIN,
"state_key": user_id,
},
retcol="room_id",
desc="get_rooms_for_user",
)

def _get_rooms_for_user_txn(
self, txn: LoggingTransaction, user_id: str
) -> FrozenSet[str]:
sql = """
SELECT room_id
FROM current_state_events AS c
WHERE
c.type = 'm.room.member'
AND c.state_key = ?
AND c.membership = ?
"""

txn.execute(sql, (user_id, Membership.JOIN))
return frozenset(row[0] for row in txn)
return frozenset(room_ids)

@cachedList(
cached_method_name="get_rooms_for_user",
Expand Down

0 comments on commit 9907aaa

Please sign in to comment.