summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-05-22 15:12:19 +0100
committerErik Johnston <erik@matrix.org>2017-05-22 15:12:19 +0100
commitbd7bb5df717810eec0ae56d558a8413003d2ecaa (patch)
tree67d05d424bfad9b420a7237046b3c773f238fcfb /synapse
parentUpdate list cache to handle one arg case (diff)
downloadsynapse-bd7bb5df717810eec0ae56d558a8413003d2ecaa.tar.xz
Pull out if statement from for loop
Diffstat (limited to 'synapse')
-rw-r--r--synapse/util/caches/descriptors.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py
index 77a0d8e35d..cbdff86596 100644
--- a/synapse/util/caches/descriptors.py
+++ b/synapse/util/caches/descriptors.py
@@ -471,14 +471,22 @@ class CacheListDescriptor(_CacheDescriptorBase):
             results = {}
             cached_defers = {}
             missing = []
+
+            # If the cache takes a single arg then that is used as the key,
+            # otherwise a tuple is used.
+            if num_args == 1:
+                def cache_get(arg):
+                    return cache.get(arg, callback=invalidate_callback)
+            else:
+                key = list(keyargs)
+
+                def cache_get(arg):
+                    key[self.list_pos] = arg
+                    return cache.get(tuple(key), callback=invalidate_callback)
+
             for arg in list_args:
                 try:
-                    if num_args == 1:
-                        res = cache.get(arg, callback=invalidate_callback)
-                    else:
-                        key = list(keyargs)
-                        key[self.list_pos] = arg
-                        res = cache.get(tuple(key), callback=invalidate_callback)
+                    res = cache_get(arg)
 
                     if not isinstance(res, ObservableDeferred):
                         results[arg] = res