Remove unnecessary maybeDeferred calls (#8044)
parent
7620912d84
commit
4e874ed593
|
@ -0,0 +1 @@
|
||||||
|
Convert various parts of the codebase to async/await.
|
|
@ -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):
|
||||||
|
|
|
@ -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")
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue