diff options
author | Erik Johnston <erikj@jki.re> | 2017-03-24 13:07:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 13:07:22 +0000 |
commit | 23e0ff840af810417cbd8855b92ab0794c25eaf8 (patch) | |
tree | b2b2bc5a3adec8dadd2f2730532868912e064ef4 | |
parent | Merge pull request #2058 from matrix-org/rav/logcontext_leaks_2 (diff) | |
parent | Cache hosts in room (diff) | |
download | synapse-23e0ff840af810417cbd8855b92ab0794c25eaf8.tar.xz |
Merge pull request #2060 from matrix-org/erikj/cache_hosts_in_room
Cache hosts in room
-rw-r--r-- | synapse/handlers/presence.py | 3 | ||||
-rw-r--r-- | synapse/storage/roommember.py | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 059260a8aa..1ede117c79 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -575,8 +575,7 @@ class PresenceHandler(object): 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) diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index 23127d3a95..367dbbbcf6 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -129,6 +129,16 @@ class RoomMemberStore(SQLBaseStore): 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): |