diff options
author | Erik Johnston <erik@matrix.org> | 2017-02-02 13:07:18 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-02-02 13:07:18 +0000 |
commit | 54a79c1d374f09049d3eb8ac531bca45d68b5f2b (patch) | |
tree | aea0e62e9e7f061b8ecc149e123c3f92881cd7c9 /synapse/storage/roommember.py | |
parent | Merge pull request #1872 from matrix-org/erikj/key_changes (diff) | |
download | synapse-54a79c1d374f09049d3eb8ac531bca45d68b5f2b.tar.xz |
Make presence.get_new_events a bit faster
We do this by caching the set of users a user shares rooms with.
Diffstat (limited to '')
-rw-r--r-- | synapse/storage/roommember.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index ee800d074f..70718f41ed 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -280,6 +280,22 @@ class RoomMemberStore(SQLBaseStore): user_id, membership_list=[Membership.JOIN], ) + @cachedInlineCallbacks(max_entries=50000, cache_context=True, iterable=True) + def get_users_who_share_room_with_user(self, user_id, cache_context): + rooms = yield self.get_rooms_for_user( + user_id, on_invalidate=cache_context.invalidate, + ) + + user_who_share_room = set() + for room in rooms: + user_ids = yield self.get_users_in_room( + room.room_id, on_invalidate=cache_context.invalidate, + ) + logger.info("Users in room: %r %r", room.room_id, user_ids) + user_who_share_room.update(user_ids) + + defer.returnValue(user_who_share_room) + def forget(self, user_id, room_id): """Indicate that user_id wishes to discard history for room_id.""" def f(txn): |