Skip to content

Commit

Permalink
Merge pull request matrix-org#2060 from matrix-org/erikj/cache_hosts_…
Browse files Browse the repository at this point in the history
…in_room

Cache hosts in room
  • Loading branch information
erikjohnston authored Mar 24, 2017
2 parents f136c89 + 7fc1f1e commit 23e0ff8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ def _get_interested_parties(self, states, calculate_remote_hosts=True):
if not local_states:
continue

users = yield self.store.get_users_in_room(room_id)
hosts = set(get_domain_from_id(u) for u in users)
hosts = yield self.store.get_hosts_in_room(room_id)

for host in hosts:
hosts_to_states.setdefault(host, []).extend(local_states)
Expand Down
10 changes: 10 additions & 0 deletions synapse/storage/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def f(txn, stream_ordering):
with self._stream_id_gen.get_next() as stream_ordering:
yield self.runInteraction("locally_reject_invite", f, stream_ordering)

@cachedInlineCallbacks(max_entries=100000, iterable=True, cache_context=True)
def get_hosts_in_room(self, room_id, cache_context):
"""Returns the set of all hosts currently in the room
"""
user_ids = yield self.get_users_in_room(
room_id, on_invalidate=cache_context.invalidate,
)
hosts = frozenset(get_domain_from_id(user_id) for user_id in user_ids)
defer.returnValue(hosts)

@cached(max_entries=500000, iterable=True)
def get_users_in_room(self, room_id):
def f(txn):
Expand Down

0 comments on commit 23e0ff8

Please sign in to comment.