diff options
author | Erik Johnston <erikj@jki.re> | 2018-07-17 11:16:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-17 11:16:59 +0100 |
commit | c7320a5564c15a8f8e37a8562a4f434a20180daf (patch) | |
tree | 91bcc61fb57e0b62787486aaba875bfa183f5a44 | |
parent | Merge pull request #3530 from matrix-org/erikj/stream_cache (diff) | |
parent | Use efficient .intersection (diff) | |
download | synapse-c7320a5564c15a8f8e37a8562a4f434a20180daf.tar.xz |
Merge pull request #3544 from matrix-org/erikj/fixup_stream_cache
Fix perf regression in PR #3530
-rw-r--r-- | changelog.d/3544.misc | 0 | ||||
-rw-r--r-- | synapse/util/caches/stream_change_cache.py | 4 | ||||
-rw-r--r-- | tests/util/test_stream_change_cache.py | 16 |
3 files changed, 19 insertions, 1 deletions
diff --git a/changelog.d/3544.misc b/changelog.d/3544.misc new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/changelog.d/3544.misc diff --git a/synapse/util/caches/stream_change_cache.py b/synapse/util/caches/stream_change_cache.py index 258655349b..f2bde74dc5 100644 --- a/synapse/util/caches/stream_change_cache.py +++ b/synapse/util/caches/stream_change_cache.py @@ -74,12 +74,14 @@ 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 = changed_entities.intersection(entities) + self.metrics.inc_hits() else: result = set(entities) diff --git a/tests/util/test_stream_change_cache.py b/tests/util/test_stream_change_cache.py index fc45baaaa0..65b0f2e6fb 100644 --- a/tests/util/test_stream_change_cache.py +++ b/tests/util/test_stream_change_cache.py @@ -178,6 +178,22 @@ class StreamChangeCacheTests(unittest.TestCase): ), ) + # Query a subset of the entries mid-way through the stream. We should + # only get back the subset. + self.assertEqual( + cache.get_entities_changed( + [ + "bar@baz.net", + ], + stream_pos=2, + ), + set( + [ + "bar@baz.net", + ] + ), + ) + def test_max_pos(self): """ StreamChangeCache.get_max_pos_of_last_change will return the most |