This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async/await get_user_id_by_threepid (#7620)
Based on #7619 async's `get_user_id_by_threepid` and its call stack.
- Loading branch information
1 parent
86d814c
commit e91abfd
Showing
4 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Convert `get_user_id_by_threepid` to async/await. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import logging | ||
import re | ||
from typing import Optional | ||
|
||
from six import iterkeys | ||
|
||
|
@@ -342,7 +343,7 @@ def is_real_user(self, user_id): | |
) | ||
return res | ||
|
||
@cachedInlineCallbacks() | ||
@cached() | ||
def is_support_user(self, user_id): | ||
"""Determines if the user is of type UserTypes.SUPPORT | ||
|
@@ -352,10 +353,9 @@ def is_support_user(self, user_id): | |
Returns: | ||
Deferred[bool]: True if user is of type UserTypes.SUPPORT | ||
""" | ||
res = yield self.db.runInteraction( | ||
return self.db.runInteraction( | ||
"is_support_user", self.is_support_user_txn, user_id | ||
) | ||
return res | ||
|
||
def is_real_user_txn(self, txn, user_id): | ||
res = self.db.simple_select_one_onecol_txn( | ||
|
@@ -516,18 +516,17 @@ def _find_next_generated_user_id(txn): | |
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def get_user_id_by_threepid(self, medium, address): | ||
async def get_user_id_by_threepid(self, medium: str, address: str) -> Optional[str]: | ||
"""Returns user id from threepid | ||
Args: | ||
medium (str): threepid medium e.g. email | ||
address (str): threepid address e.g. [email protected] | ||
medium: threepid medium e.g. email | ||
address: threepid address e.g. [email protected] | ||
Returns: | ||
Deferred[str|None]: user id or None if no user id/threepid mapping exists | ||
The user ID or None if no user id/threepid mapping exists | ||
""" | ||
user_id = yield self.db.runInteraction( | ||
user_id = await self.db.runInteraction( | ||
"get_user_id_by_threepid", self.get_user_id_by_threepid_txn, medium, address | ||
) | ||
return user_id | ||
|
@@ -993,7 +992,7 @@ def register_user( | |
Args: | ||
user_id (str): The desired user ID to register. | ||
password_hash (str): Optional. The password hash for this user. | ||
password_hash (str|None): Optional. The password hash for this user. | ||
was_guest (bool): Optional. Whether this is a guest account being | ||
upgraded to a non-guest account. | ||
make_guest (boolean): True if the the new user should be guest, | ||
|
@@ -1007,6 +1006,9 @@ def register_user( | |
Raises: | ||
StoreError if the user_id could not be registered. | ||
Returns: | ||
Deferred | ||
""" | ||
return self.db.runInteraction( | ||
"register_user", | ||
|