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 #543 from matrix-org/erikj/sync
Browse files Browse the repository at this point in the history
Cache get_room_changes_for_user
  • Loading branch information
erikjohnston committed Feb 1, 2016
2 parents 498c2e6 + 25c311e commit 2d3837b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions synapse/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def __init__(self, db_conn, hs):
prefilled_cache=event_cache_prefill,
)

self._membership_stream_cache = StreamChangeCache(
"MembershipStreamChangeCache", events_max,
)

account_max = self._account_data_id_gen.get_max_token(None)
self._account_data_stream_cache = StreamChangeCache(
"AccountDataAndTagsChangeCache", account_max,
Expand Down
4 changes: 4 additions & 0 deletions synapse/storage/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def _store_room_members_txn(self, txn, events):
txn.call_after(self.get_rooms_for_user.invalidate, (event.state_key,))
txn.call_after(self.get_joined_hosts_for_room.invalidate, (event.room_id,))
txn.call_after(self.get_users_in_room.invalidate, (event.room_id,))
txn.call_after(
self._membership_stream_cache.entity_has_changed,
event.state_key, event.internal_metadata.stream_ordering
)

def get_room_member(self, user_id, room_id):
"""Retrieve the current state of a room member.
Expand Down
7 changes: 7 additions & 0 deletions synapse/storage/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ def get_room_changes_for_user(self, user_id, from_key, to_key):
if from_key == to_key:
return defer.succeed([])

if from_id:
has_changed = self._membership_stream_cache.has_entity_changed(
user_id, int(from_id)
)
if not has_changed:
return defer.succeed([])

def f(txn):
if from_id is not None:
sql = (
Expand Down

0 comments on commit 2d3837b

Please sign in to comment.