Skip to content

Commit

Permalink
Convert remote key resource REST layer to async/await. (matrix-org#7020)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored and phil-flex committed Mar 27, 2020
1 parent 79ca774 commit bb8e7d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/7020.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port `synapse.rest.keys` to async/await.
11 changes: 4 additions & 7 deletions synapse/rest/key/v2/remote_key_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from canonicaljson import encode_canonical_json, json
from signedjson.sign import sign_json

from twisted.internet import defer

from synapse.api.errors import Codes, SynapseError
from synapse.crypto.keyring import ServerKeyFetcher
from synapse.http.server import (
Expand Down Expand Up @@ -125,8 +123,7 @@ async def _async_render_POST(self, request):

await self.query_keys(request, query, query_remote_on_cache_miss=True)

@defer.inlineCallbacks
def query_keys(self, request, query, query_remote_on_cache_miss=False):
async def query_keys(self, request, query, query_remote_on_cache_miss=False):
logger.info("Handling query for keys %r", query)

store_queries = []
Expand All @@ -143,7 +140,7 @@ def query_keys(self, request, query, query_remote_on_cache_miss=False):
for key_id in key_ids:
store_queries.append((server_name, key_id, None))

cached = yield self.store.get_server_keys_json(store_queries)
cached = await self.store.get_server_keys_json(store_queries)

json_results = set()

Expand Down Expand Up @@ -215,8 +212,8 @@ def query_keys(self, request, query, query_remote_on_cache_miss=False):
json_results.add(bytes(result["key_json"]))

if cache_misses and query_remote_on_cache_miss:
yield self.fetcher.get_keys(cache_misses)
yield self.query_keys(request, query, query_remote_on_cache_miss=False)
await self.fetcher.get_keys(cache_misses)
await self.query_keys(request, query, query_remote_on_cache_miss=False)
else:
signed_keys = []
for key_json in json_results:
Expand Down

0 comments on commit bb8e7d7

Please sign in to comment.