Skip to content
Snippets Groups Projects
Unverified Commit c7320a55 authored by Erik Johnston's avatar Erik Johnston Committed by GitHub
Browse files

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

Fix perf regression in PR #3530
parents 3fe0938b b2aa05a8
No related branches found
No related tags found
No related merge requests found
...@@ -74,12 +74,14 @@ class StreamChangeCache(object): ...@@ -74,12 +74,14 @@ class StreamChangeCache(object):
assert type(stream_pos) is int assert type(stream_pos) is int
if stream_pos >= self._earliest_known_stream_pos: if stream_pos >= self._earliest_known_stream_pos:
result = { changed_entities = {
self._cache[k] for k in self._cache.islice( self._cache[k] for k in self._cache.islice(
start=self._cache.bisect_right(stream_pos), start=self._cache.bisect_right(stream_pos),
) )
} }
result = changed_entities.intersection(entities)
self.metrics.inc_hits() self.metrics.inc_hits()
else: else:
result = set(entities) result = set(entities)
......
...@@ -178,6 +178,22 @@ class StreamChangeCacheTests(unittest.TestCase): ...@@ -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): def test_max_pos(self):
""" """
StreamChangeCache.get_max_pos_of_last_change will return the most StreamChangeCache.get_max_pos_of_last_change will return the most
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment