summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-06-02 11:52:32 +0100
committerErik Johnston <erik@matrix.org>2016-06-02 11:52:32 +0100
commit105f17ff4ab7719e11fa143b2547240d402a4c6b (patch)
treee0eec596d17c710c94d997835cd1ec66762157b2
parentChange CacheMetrics to be quicker (diff)
downloadsynapse-105f17ff4ab7719e11fa143b2547240d402a4c6b.tar.xz
Small optimisation to CacheListDescriptor
-rw-r--r--synapse/util/async.py9
-rw-r--r--synapse/util/caches/descriptors.py4
2 files changed, 11 insertions, 2 deletions
diff --git a/synapse/util/async.py b/synapse/util/async.py
index 0d6f48e2d8..40be7fe7e3 100644
--- a/synapse/util/async.py
+++ b/synapse/util/async.py
@@ -102,6 +102,15 @@ class ObservableDeferred(object):
     def observers(self):
         return self._observers
 
+    def has_called(self):
+        return self._result is not None
+
+    def has_succeeded(self):
+        return self._result is not None and self._result[0] is True
+
+    def get_result(self):
+        return self._result[1]
+
     def __getattr__(self, name):
         return getattr(self._deferred, name)
 
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py
index f48ff29c6a..31c2632573 100644
--- a/synapse/util/caches/descriptors.py
+++ b/synapse/util/caches/descriptors.py
@@ -321,12 +321,12 @@ class CacheListDescriptor(object):
 
                 try:
                     res = cache.get(tuple(key))
-                    if not res.called:
+                    if not res.has_succeeded():
                         res = res.observe()
                         res.addCallback(lambda r, arg: (arg, r), arg)
                         cached_defers[arg] = res
                     else:
-                        results[arg] = res.result
+                        results[arg] = res.get_result()
                 except KeyError:
                     missing.append(arg)