Also cache user_id -> UserID conversion

This commit is contained in:
Erik Johnston 2015-06-01 14:55:02 +01:00
parent 072a1467f2
commit b6b8e2dcbf
3 changed files with 9 additions and 10 deletions

View file

@ -255,17 +255,8 @@ class RoomMemberHandler(BaseHandler):
self.distributor.declare("user_joined_room") self.distributor.declare("user_joined_room")
self.distributor.declare("user_left_room") self.distributor.declare("user_left_room")
@defer.inlineCallbacks
def get_room_members(self, room_id): def get_room_members(self, room_id):
users = yield self.store.get_users_in_room(room_id) return self.store.get_user_objs_in_room(room_id)
start = time.time()
users = [UserID.from_string(u) for u in users]
end = time.time()
RoomMemberHandler.total_time += end-start
defer.returnValue(users)
@defer.inlineCallbacks @defer.inlineCallbacks
def fetch_room_distributions_into(self, room_id, localusers=None, def fetch_room_distributions_into(self, room_id, localusers=None,

View file

@ -128,6 +128,7 @@ class EventsStore(SQLBaseStore):
txn.call_after(self.get_current_state_for_key.invalidate_all) txn.call_after(self.get_current_state_for_key.invalidate_all)
txn.call_after(self.get_rooms_for_user.invalidate_all) txn.call_after(self.get_rooms_for_user.invalidate_all)
txn.call_after(self.get_users_in_room.invalidate, event.room_id) txn.call_after(self.get_users_in_room.invalidate, event.room_id)
txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id)
txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id) txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id)
txn.call_after(self.get_room_name_and_aliases, event.room_id) txn.call_after(self.get_room_name_and_aliases, event.room_id)

View file

@ -67,6 +67,7 @@ class RoomMemberStore(SQLBaseStore):
txn.call_after(self.get_rooms_for_user.invalidate, target_user_id) txn.call_after(self.get_rooms_for_user.invalidate, target_user_id)
txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id) txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id)
txn.call_after(self.get_users_in_room.invalidate, event.room_id) txn.call_after(self.get_users_in_room.invalidate, event.room_id)
txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id)
def get_room_member(self, user_id, room_id): def get_room_member(self, user_id, room_id):
"""Retrieve the current state of a room member. """Retrieve the current state of a room member.
@ -101,6 +102,12 @@ class RoomMemberStore(SQLBaseStore):
return [r["user_id"] for r in rows] return [r["user_id"] for r in rows]
return self.runInteraction("get_users_in_room", f) return self.runInteraction("get_users_in_room", f)
@cached()
def get_user_objs_in_room(self, room_id):
return self.get_users_in_room(room_id).addCallback(
lambda users: [UserID.from_string(u) for u in users]
)
def get_room_members(self, room_id, membership=None): def get_room_members(self, room_id, membership=None):
"""Retrieve the current room member list for a room. """Retrieve the current room member list for a room.