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

Speed up remote invite rejection database call #8815

Merged
merged 6 commits into from
Nov 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,37 +363,25 @@ async def get_local_current_membership_for_user_in_room(
Returns:
A tuple of (membership_type, event_id). Both will be None if a
room_id/user_id pair is not found.

"""
return await self.db_pool.runInteraction(
"get_local_current_membership_for_user_in_room",
self._get_local_current_membership_for_user_in_room_txn,
user_id,
room_id,
)

def _get_local_current_membership_for_user_in_room_txn(
self, txn, user_id: str, room_id: str
) -> Tuple[Optional[str], Optional[str]]:
# Paranoia check.
if not self.hs.is_mine_id(user_id):
raise Exception(
"Cannot call 'get_local_current_membership_for_user_in_room' on "
"non-local user %s" % (user_id,),
)

sql = """
SELECT membership, event_id
FROM local_current_membership
WHERE
room_id = ? AND user_id = ?
"""
results_dict = await self.db_pool.simple_select_one(
"local_current_membership",
{"room_id": room_id, "user_id": user_id},
("membership", "event_id"),
allow_none=True,
desc="get_local_current_membership_for_user_in_room",
)
if not results_dict:
return None, None

txn.execute(sql, (room_id, user_id))
row = txn.fetchone()
if row:
return row[0], row[1]
return None, None
return results_dict.get("membership"), results_dict.get("event_id")
clokep marked this conversation as resolved.
Show resolved Hide resolved

@cached(max_entries=500000, iterable=True)
async def get_rooms_for_user_with_stream_ordering(
Expand Down