Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3544 from matrix-org/erikj/fixup_stream_cache
Browse files Browse the repository at this point in the history
Fix perf regression in PR #3530
  • Loading branch information
erikjohnston authored Jul 17, 2018
2 parents 3fe0938 + b2aa05a commit c7320a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Empty file added changelog.d/3544.misc
Empty file.
4 changes: 3 additions & 1 deletion synapse/util/caches/stream_change_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ def get_entities_changed(self, entities, stream_pos):
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)
Expand Down
16 changes: 16 additions & 0 deletions tests/util/test_stream_change_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ def test_get_entities_changed(self):
),
)

# 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
Expand Down

0 comments on commit c7320a5

Please sign in to comment.