summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-03-28 10:41:08 +0100
committerErik Johnston <erik@matrix.org>2017-03-30 14:14:36 +0100
commit86780a8bc3eac566d2c03a601f84b5ccf5737ceb (patch)
tree196cf1307a234245d4d1642509f64a2f98c09ca5 /synapse
parentFix the logcontext handling in the cache wrappers (#2077) (diff)
downloadsynapse-86780a8bc3eac566d2c03a601f84b5ccf5737ceb.tar.xz
Don't convert to deferreds when not necessary
Diffstat (limited to 'synapse')
-rw-r--r--synapse/push/push_tools.py7
-rw-r--r--synapse/util/async.py2
-rw-r--r--synapse/util/caches/descriptors.py5
-rw-r--r--synapse/util/logcontext.py3
-rw-r--r--synapse/visibility.py3
5 files changed, 12 insertions, 8 deletions
diff --git a/synapse/push/push_tools.py b/synapse/push/push_tools.py
index 287df94b4f..6835f54e97 100644
--- a/synapse/push/push_tools.py
+++ b/synapse/push/push_tools.py
@@ -17,15 +17,12 @@ from twisted.internet import defer
 from synapse.push.presentable_names import (
     calculate_room_name, name_from_member_event
 )
-from synapse.util.logcontext import preserve_fn, preserve_context_over_deferred
 
 
 @defer.inlineCallbacks
 def get_badge_count(store, user_id):
-    invites, joins = yield preserve_context_over_deferred(defer.gatherResults([
-        preserve_fn(store.get_invited_rooms_for_user)(user_id),
-        preserve_fn(store.get_rooms_for_user)(user_id),
-    ], consumeErrors=True))
+    invites = yield store.get_invited_rooms_for_user(user_id)
+    joins = yield store.get_rooms_for_user(user_id)
 
     my_receipts_by_room = yield store.get_receipts_for_user(
         user_id, "m.read",
diff --git a/synapse/util/async.py b/synapse/util/async.py
index 35380bf8ed..8495de496a 100644
--- a/synapse/util/async.py
+++ b/synapse/util/async.py
@@ -101,7 +101,7 @@ class ObservableDeferred(object):
             return d
         else:
             success, res = self._result
-            return defer.succeed(res) if success else defer.fail(res)
+            return res if success else defer.fail(res)
 
     def observers(self):
         return self._observers
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py
index 5c30ed235d..1607978e29 100644
--- a/synapse/util/caches/descriptors.py
+++ b/synapse/util/caches/descriptors.py
@@ -341,7 +341,10 @@ class CacheDescriptor(_CacheDescriptorBase):
                 cache.set(cache_key, result_d, callback=invalidate_callback)
                 observer = result_d.observe()
 
-            return logcontext.make_deferred_yieldable(observer)
+            if isinstance(observer, defer.Deferred):
+                return logcontext.make_deferred_yieldable(observer)
+            else:
+                return observer
 
         wrapped.invalidate = cache.invalidate
         wrapped.invalidate_all = cache.invalidate_all
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py
index 857afee7cb..183d9cf62f 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -315,6 +315,9 @@ def preserve_context_over_deferred(deferred, context=None):
     the deferred follow the synapse logcontext rules: try
     ``make_deferred_yieldable`` instead.
     """
+    if not isinstance(deferred, defer.Deferred):
+        return deferred
+
     if context is None:
         context = LoggingContext.current_context()
     d = _PreservingContextDeferred(context)
diff --git a/synapse/visibility.py b/synapse/visibility.py
index 31659156ae..c4dd9ae2c7 100644
--- a/synapse/visibility.py
+++ b/synapse/visibility.py
@@ -56,7 +56,8 @@ def filter_events_for_clients(store, user_tuples, events, event_id_to_state):
         events ([synapse.events.EventBase]): list of events to filter
     """
     forgotten = yield preserve_context_over_deferred(defer.gatherResults([
-        preserve_fn(store.who_forgot_in_room)(
+        defer.maybeDeferred(
+            preserve_fn(store.who_forgot_in_room),
             room_id,
         )
         for room_id in frozenset(e.room_id for e in events)