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
Do not assume calls to runInteraction return Deferreds. #8133
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 various parts of the codebase 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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
import itertools | ||
import logging | ||
from typing import Iterable, Tuple | ||
|
||
from signedjson.key import decode_verify_key_bytes | ||
|
||
|
@@ -88,7 +89,12 @@ def _txn(txn): | |
|
||
return self.db_pool.runInteraction("get_server_verify_keys", _txn) | ||
|
||
def store_server_verify_keys(self, from_server, ts_added_ms, verify_keys): | ||
async def store_server_verify_keys( | ||
self, | ||
from_server: str, | ||
ts_added_ms: int, | ||
verify_keys: Iterable[Tuple[str, str, FetchKeyResult]], | ||
) -> None: | ||
"""Stores NACL verification keys for remote servers. | ||
Args: | ||
from_server (str): Where the verification keys were looked up | ||
|
@@ -115,13 +121,7 @@ def store_server_verify_keys(self, from_server, ts_added_ms, verify_keys): | |
# param, which is itself the 2-tuple (server_name, key_id). | ||
invalidations.append((server_name, key_id)) | ||
|
||
def _invalidate(res): | ||
f = self._get_server_verify_key.invalidate | ||
for i in invalidations: | ||
f((i,)) | ||
return res | ||
Comment on lines
-118
to
-122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There's no reason to store this and return it, it makes it more confusing. |
||
|
||
return self.db_pool.runInteraction( | ||
await self.db_pool.runInteraction( | ||
"store_server_verify_keys", | ||
self.db_pool.simple_upsert_many_txn, | ||
table="server_signature_keys", | ||
|
@@ -134,7 +134,11 @@ def _invalidate(res): | |
"verify_key", | ||
), | ||
value_values=value_values, | ||
).addCallback(_invalidate) | ||
) | ||
|
||
invalidate = self._get_server_verify_key.invalidate | ||
for i in invalidations: | ||
invalidate((i,)) | ||
|
||
def store_server_keys_json( | ||
self, server_name, key_id, from_server, ts_now_ms, ts_expires_ms, key_json_bytes | ||
|
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 |
---|---|---|
|
@@ -13,30 +13,29 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import operator | ||
|
||
from synapse.storage._base import SQLBaseStore | ||
from synapse.util.caches.descriptors import cached, cachedList | ||
|
||
|
||
class UserErasureWorkerStore(SQLBaseStore): | ||
@cached() | ||
def is_user_erased(self, user_id): | ||
async def is_user_erased(self, user_id: str) -> bool: | ||
""" | ||
Check if the given user id has requested erasure | ||
|
||
Args: | ||
user_id (str): full user id to check | ||
user_id: full user id to check | ||
|
||
Returns: | ||
Deferred[bool]: True if the user has requested erasure | ||
True if the user has requested erasure | ||
""" | ||
return self.db_pool.simple_select_onecol( | ||
result = await self.db_pool.simple_select_onecol( | ||
table="erased_users", | ||
keyvalues={"user_id": user_id}, | ||
retcol="1", | ||
desc="is_user_erased", | ||
).addCallback(operator.truth) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
return bool(result) | ||
|
||
@cachedList(cached_method_name="is_user_erased", list_name="user_ids") | ||
async def are_users_erased(self, user_ids): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been in #8100.