diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2023-11-09 11:13:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-09 11:13:31 -0500 |
commit | ab3f1b3b53cdb4e2751b3e8c5eb052d7475be58f (patch) | |
tree | d8f032a9833f5998626f67c9103768d6b77b4945 /synapse/storage/databases/main/user_directory.py | |
parent | Return attrs for more media repo APIs. (#16611) (diff) | |
download | synapse-ab3f1b3b53cdb4e2751b3e8c5eb052d7475be58f.tar.xz |
Convert simple_select_one_txn and simple_select_one to return tuples. (#16612)
Diffstat (limited to 'synapse/storage/databases/main/user_directory.py')
-rw-r--r-- | synapse/storage/databases/main/user_directory.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index a9f5d68b63..1a38f3d785 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -20,7 +20,6 @@ from typing import ( Collection, Iterable, List, - Mapping, Optional, Sequence, Set, @@ -833,13 +832,25 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore): "delete_all_from_user_dir", _delete_all_from_user_dir_txn ) - async def _get_user_in_directory(self, user_id: str) -> Optional[Mapping[str, str]]: - return await self.db_pool.simple_select_one( - table="user_directory", - keyvalues={"user_id": user_id}, - retcols=("display_name", "avatar_url"), - allow_none=True, - desc="get_user_in_directory", + async def _get_user_in_directory( + self, user_id: str + ) -> Optional[Tuple[Optional[str], Optional[str]]]: + """ + Fetch the user information in the user directory. + + Returns: + None if the user is unknown, otherwise a tuple of display name and + avatar URL (both of which may be None). + """ + return cast( + Optional[Tuple[Optional[str], Optional[str]]], + await self.db_pool.simple_select_one( + table="user_directory", + keyvalues={"user_id": user_id}, + retcols=("display_name", "avatar_url"), + allow_none=True, + desc="get_user_in_directory", + ), ) async def update_user_directory_stream_pos(self, stream_id: Optional[int]) -> None: |