From 6957bfdca6658114526033e839ceec38b988a323 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Mar 2017 11:51:46 +0000 Subject: Don't recreate so many sets --- synapse/storage/roommember.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'synapse/storage') diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index 545d3d3a99..5f044a3f18 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -274,24 +274,25 @@ class RoomMemberStore(SQLBaseStore): return rows - @cached(max_entries=500000, iterable=True) + @cachedInlineCallbacks(max_entries=500000, iterable=True) def get_rooms_for_user(self, user_id): - return self.get_rooms_for_user_where_membership_is( + rooms = yield self.get_rooms_for_user_where_membership_is( user_id, membership_list=[Membership.JOIN], ) + defer.returnValue(frozenset(r.room_id for r in rooms)) @cachedInlineCallbacks(max_entries=500000, cache_context=True, iterable=True) def get_users_who_share_room_with_user(self, user_id, cache_context): """Returns the set of users who share a room with `user_id` """ - rooms = yield self.get_rooms_for_user( + room_ids = yield self.get_rooms_for_user( user_id, on_invalidate=cache_context.invalidate, ) user_who_share_room = set() - for room in rooms: + for room_id in room_ids: user_ids = yield self.get_users_in_room( - room.room_id, on_invalidate=cache_context.invalidate, + room_id, on_invalidate=cache_context.invalidate, ) user_who_share_room.update(user_ids) -- cgit 1.4.1 From da146657c9a8685eb927cd295891332af86ba15d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Mar 2017 13:04:07 +0000 Subject: Comments --- synapse/handlers/sync.py | 4 ++-- synapse/storage/roommember.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'synapse/storage') diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 3dbedb2c40..c0205da1a9 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -832,8 +832,8 @@ class SyncHandler(object): @defer.inlineCallbacks def _have_rooms_changed(self, sync_result_builder): - """Returns whether any rooms have changed since the sync. Must be an - incremental sync + """Returns whether there may be any new events that should be sent down + the sync. Returns True if there are. """ user_id = sync_result_builder.sync_config.user.to_string() since_token = sync_result_builder.since_token diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index 5f044a3f18..e38d8927bf 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -276,6 +276,8 @@ class RoomMemberStore(SQLBaseStore): @cachedInlineCallbacks(max_entries=500000, iterable=True) def get_rooms_for_user(self, user_id): + """Returns a set of room_ids the user is currently joined to + """ rooms = yield self.get_rooms_for_user_where_membership_is( user_id, membership_list=[Membership.JOIN], ) -- cgit 1.4.1