summary refs log tree commit diff
path: root/synapse/storage/database.py
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2020-08-19 07:09:24 -0400
committerGitHub <noreply@github.com>2020-08-19 07:09:24 -0400
commitd89692ea843f5c67c87ac4c992575015b359c5a0 (patch)
treee3d65223eafba87204876ba97a4314b4034e387d /synapse/storage/database.py
parentRemove the unused inlineCallbacks code-paths in the caching code (#8119) (diff)
downloadsynapse-d89692ea843f5c67c87ac4c992575015b359c5a0.tar.xz
Convert runWithConnection to async. (#8121)
Diffstat (limited to 'synapse/storage/database.py')
-rw-r--r--synapse/storage/database.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py
index 8a9e06efcf..b9aef96b08 100644
--- a/synapse/storage/database.py
+++ b/synapse/storage/database.py
@@ -516,14 +516,16 @@ class DatabasePool(object):
             logger.warning("Starting db txn '%s' from sentinel context", desc)
 
         try:
-            result = yield self.runWithConnection(
-                self.new_transaction,
-                desc,
-                after_callbacks,
-                exception_callbacks,
-                func,
-                *args,
-                **kwargs
+            result = yield defer.ensureDeferred(
+                self.runWithConnection(
+                    self.new_transaction,
+                    desc,
+                    after_callbacks,
+                    exception_callbacks,
+                    func,
+                    *args,
+                    **kwargs
+                )
             )
 
             for after_callback, after_args, after_kwargs in after_callbacks:
@@ -535,8 +537,7 @@ class DatabasePool(object):
 
         return result
 
-    @defer.inlineCallbacks
-    def runWithConnection(self, func: Callable, *args: Any, **kwargs: Any):
+    async def runWithConnection(self, func: Callable, *args: Any, **kwargs: Any) -> Any:
         """Wraps the .runWithConnection() method on the underlying db_pool.
 
         Arguments:
@@ -547,7 +548,7 @@ class DatabasePool(object):
             kwargs: named args to pass to `func`
 
         Returns:
-            Deferred: The result of func
+            The result of func
         """
         parent_context = current_context()  # type: Optional[LoggingContextOrSentinel]
         if not parent_context:
@@ -570,12 +571,10 @@ class DatabasePool(object):
 
                 return func(conn, *args, **kwargs)
 
-        result = yield make_deferred_yieldable(
+        return await make_deferred_yieldable(
             self._db_pool.runWithConnection(inner_func, *args, **kwargs)
         )
 
-        return result
-
     @staticmethod
     def cursor_to_dict(cursor):
         """Converts a SQL cursor into an list of dicts.