diff options
author | Erik Johnston <erik@matrix.org> | 2017-05-22 15:12:19 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-05-22 15:12:19 +0100 |
commit | bd7bb5df717810eec0ae56d558a8413003d2ecaa (patch) | |
tree | 67d05d424bfad9b420a7237046b3c773f238fcfb /synapse/util/caches | |
parent | Update list cache to handle one arg case (diff) | |
download | synapse-bd7bb5df717810eec0ae56d558a8413003d2ecaa.tar.xz |
Pull out if statement from for loop
Diffstat (limited to 'synapse/util/caches')
-rw-r--r-- | synapse/util/caches/descriptors.py | 20 |
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 |