diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-05-18 18:21:06 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-05-18 18:21:06 +0100 |
commit | e4c65b338d44fadc058cbd8e4cd79ae1601d3526 (patch) | |
tree | 74a0bd22f21de76c43b0436f2dd03ea887555410 /synapse/handlers/presence.py | |
parent | Cache the most recent serial for each room (diff) | |
download | synapse-e4c65b338d44fadc058cbd8e4cd79ae1601d3526.tar.xz |
Speed up the get_pagination_rows as well
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/presence.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index aa1d73f2f9..6537a37385 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -1154,14 +1154,28 @@ class PresenceEventSource(object): presence = self.hs.get_handlers().presence_handler cachemap = presence._user_cachemap + user_ids_to_check = {user} + presence_list = yield presence.store.get_presence_list( + user.localpart, accepted=True + ) + if presence_list is None: + presence_list = () + user_ids_to_check |= set( + UserID.from_string(p["observed_user_id"]) for p in presence_list + ) + room_ids = yield presence.get_joined_rooms_for_user(user) + for room_id in set(room_ids) & set(presence._room_serials): + if presence._room_serials[room_id] >= from_key: + joined = yield presence.get_joined_users_for_room_id(room_id) + user_ids_to_check |= set(joined) + updates = [] # TODO(paul): use a DeferredList ? How to limit concurrency. - for observed_user in cachemap.keys(): + for observed_user in user_ids_to_check & set(cachemap): if not (to_key < cachemap[observed_user].serial <= from_key): continue - if (yield self.is_visible(observer_user, observed_user)): - updates.append((observed_user, cachemap[observed_user])) + updates.append((observed_user, cachemap[observed_user])) # TODO(paul): limit |