summary refs log tree commit diff
path: root/synapse/util/caches/stream_change_cache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-06-09 11:39:35 +0100
committerErik Johnston <erik@matrix.org>2017-06-09 11:44:01 +0100
commiteed59dcc1efdda95ea2deaad6dd8b70e5d346a6e (patch)
treebedbae765a51c4660b0ffcf567cc570b528279b9 /synapse/util/caches/stream_change_cache.py
parentMerge pull request #2263 from matrix-org/erikj/fix_state_woes (diff)
downloadsynapse-eed59dcc1efdda95ea2deaad6dd8b70e5d346a6e.tar.xz
Fix has_any_entity_changed
Occaisonally has_any_entity_changed would throw the error: "Set changed
size during iteration" when taking the max of the `sorteddict`. While
its uncertain how that happens, its quite inefficient to iterate over
the entire dict anyway so we change to using the more traditional
`bisect_*` functions.
Diffstat (limited to 'synapse/util/caches/stream_change_cache.py')
-rw-r--r--synapse/util/caches/stream_change_cache.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/synapse/util/caches/stream_change_cache.py b/synapse/util/caches/stream_change_cache.py
index c498aee46c..b723e33641 100644
--- a/synapse/util/caches/stream_change_cache.py
+++ b/synapse/util/caches/stream_change_cache.py
@@ -96,10 +96,10 @@ class StreamChangeCache(object):
 
         if stream_pos >= self._earliest_known_stream_pos:
             self.metrics.inc_hits()
-            if stream_pos >= max(self._cache):
-                return False
-            else:
-                return True
+            keys = self._cache.keys()
+            i = keys.bisect_right(stream_pos)
+
+            return len(keys[i:]) > 0
         else:
             self.metrics.inc_misses()
             return True