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

Fix perf regression in PR #3530 #3544

Merged
merged 4 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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