Remove unnecessary maybeDeferred calls (#8044)

This commit is contained in:
Patrick Cloke 2020-08-07 09:44:48 -04:00 committed by GitHub
parent 7620912d84
commit 4e874ed593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 7 deletions

1
changelog.d/8044.misc Normal file
View File

@ -0,0 +1 @@
Convert various parts of the codebase to async/await.

View File

@ -665,7 +665,7 @@ class RegisterRestServlet(RestServlet):
(object) params: registration parameters, from which we pull (object) params: registration parameters, from which we pull
device_id, initial_device_name and inhibit_login device_id, initial_device_name and inhibit_login
Returns: Returns:
defer.Deferred: (object) dictionary for response from /register (object) dictionary for response from /register
""" """
result = {"user_id": user_id, "home_server": self.hs.hostname} result = {"user_id": user_id, "home_server": self.hs.hostname}
if not params.get("inhibit_login", False): if not params.get("inhibit_login", False):

View File

@ -22,8 +22,6 @@ from os import path
import jinja2 import jinja2
from jinja2 import TemplateNotFound from jinja2 import TemplateNotFound
from twisted.internet import defer
from synapse.api.errors import NotFoundError, StoreError, SynapseError from synapse.api.errors import NotFoundError, StoreError, SynapseError
from synapse.config import ConfigError from synapse.config import ConfigError
from synapse.http.server import DirectServeHtmlResource, respond_with_html from synapse.http.server import DirectServeHtmlResource, respond_with_html
@ -135,7 +133,7 @@ class ConsentResource(DirectServeHtmlResource):
else: else:
qualified_user_id = UserID(username, self.hs.hostname).to_string() qualified_user_id = UserID(username, self.hs.hostname).to_string()
u = await defer.maybeDeferred(self.store.get_user_by_id, qualified_user_id) u = await self.store.get_user_by_id(qualified_user_id)
if u is None: if u is None:
raise NotFoundError("Unknown user") raise NotFoundError("Unknown user")

View File

@ -28,7 +28,6 @@ from urllib import parse as urlparse
import attr import attr
from twisted.internet import defer
from twisted.internet.error import DNSLookupError from twisted.internet.error import DNSLookupError
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
@ -228,7 +227,7 @@ class PreviewUrlResource(DirectServeJsonResource):
else: else:
logger.info("Returning cached response") logger.info("Returning cached response")
og = await make_deferred_yieldable(defer.maybeDeferred(observable.observe)) og = await make_deferred_yieldable(observable.observe())
respond_with_json_bytes(request, 200, og, send_cors=True) respond_with_json_bytes(request, 200, og, send_cors=True)
async def _do_preview(self, url: str, user: str, ts: int) -> bytes: async def _do_preview(self, url: str, user: str, ts: int) -> bytes:

View File

@ -192,7 +192,7 @@ class Cache(object):
callbacks = [callback] if callback else [] callbacks = [callback] if callback else []
self.check_thread() self.check_thread()
observable = ObservableDeferred(value, consumeErrors=True) observable = ObservableDeferred(value, consumeErrors=True)
observer = defer.maybeDeferred(observable.observe) observer = observable.observe()
entry = CacheEntry(deferred=observable, callbacks=callbacks) entry = CacheEntry(deferred=observable, callbacks=callbacks)
existing_entry = self._pending_deferred_cache.pop(key, None) existing_entry = self._pending_deferred_cache.pop(key, None)