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

async/await get_user_id_by_threepid #7620

Merged
merged 6 commits into from
Jun 3, 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
22 changes: 12 additions & 10 deletions synapse/storage/data_stores/main/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import logging
import re
from typing import Optional

from six import iterkeys

Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down