summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-07-17 10:27:51 +0100
committerErik Johnston <erik@matrix.org>2018-07-17 10:27:51 +0100
commit547b1355d3747b267db3e21aefd143382f49f4ec (patch)
treeac4fbb3cb89b3b72d1f87d20cf0565db8c4c011a
parentMerge pull request #3530 from matrix-org/erikj/stream_cache (diff)
downloadsynapse-547b1355d3747b267db3e21aefd143382f49f4ec.tar.xz
Fix perf regression in PR #3530
The get_entities_changed function was changed to return all changed
entities since the given stream position, rather than only those changed
from a given list of entities. This resulted in the function incorrectly
returning large numbers of entities that, for example, caused large
increases in database usage.
-rw-r--r--synapse/util/caches/stream_change_cache.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/synapse/util/caches/stream_change_cache.py b/synapse/util/caches/stream_change_cache.py
index 258655349b..c1e76b1a0e 100644
--- a/synapse/util/caches/stream_change_cache.py
+++ b/synapse/util/caches/stream_change_cache.py
@@ -74,12 +74,17 @@ class StreamChangeCache(object):
         assert type(stream_pos) is int
 
         if stream_pos >= self._earliest_known_stream_pos:
-            result = {
+            changed_entities = {
                 self._cache[k] for k in self._cache.islice(
                     start=self._cache.bisect_right(stream_pos),
                 )
             }
 
+            result = {
+                e for e in entities
+                if e in changed_entities
+            }
+
             self.metrics.inc_hits()
         else:
             result = set(entities)