summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-07-12 12:08:49 +0100
committerGitHub <noreply@github.com>2018-07-12 12:08:49 +0100
commit6dff49b8a95646f80401334b16644b88bc6f517e (patch)
tree0261c2f6e5b59754bd15e6c2919e87ed8ebd5821
parentMerge pull request #3316 from matrix-org/rav/enforce_report_api (diff)
parentchangelog (diff)
downloadsynapse-6dff49b8a95646f80401334b16644b88bc6f517e.tar.xz
Merge pull request #3521 from matrix-org/rav/optimise_stream_change_cache
Reduce set building in get_entities_changed
-rw-r--r--changelog.d/3521.feature1
-rw-r--r--synapse/util/caches/stream_change_cache.py20
2 files changed, 13 insertions, 8 deletions
diff --git a/changelog.d/3521.feature b/changelog.d/3521.feature
new file mode 100644
index 0000000000..6dced5f2ae
--- /dev/null
+++ b/changelog.d/3521.feature
@@ -0,0 +1 @@
+Cache optimisation for /sync requests
\ No newline at end of file
diff --git a/synapse/util/caches/stream_change_cache.py b/synapse/util/caches/stream_change_cache.py
index 8637867c6d..a1f8ff8f10 100644
--- a/synapse/util/caches/stream_change_cache.py
+++ b/synapse/util/caches/stream_change_cache.py
@@ -74,14 +74,18 @@ class StreamChangeCache(object):
         assert type(stream_pos) is int
 
         if stream_pos >= self._earliest_known_stream_pos:
-            not_known_entities = set(entities) - set(self._entity_to_key)
-
-            result = (
-                {self._cache[k] for k in self._cache.islice(
-                    start=self._cache.bisect_right(stream_pos))}
-                .intersection(entities)
-                .union(not_known_entities)
-            )
+            changed_entities = {
+                self._cache[k] for k in self._cache.islice(
+                    start=self._cache.bisect_right(stream_pos),
+                )
+            }
+
+            # we need to include entities which we don't know about, as well as
+            # those which are known to have changed since the stream pos.
+            result = {
+                e for e in entities
+                if e in changed_entities or e not in self._entity_to_key
+            }
 
             self.metrics.inc_hits()
         else: