Merge pull request #3544 from matrix-org/erikj/fixup_stream_cache

Fix perf regression in PR #3530
This commit is contained in:
Erik Johnston 2018-07-17 11:16:59 +01:00 committed by GitHub
commit c7320a5564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

0
changelog.d/3544.misc Normal file
View File

View File

@ -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)

View File

@ -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