diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 8bf87f38f7..30ff87a4c4 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -930,6 +930,10 @@ class EventsStore(EventFederationStore, EventsWorkerStore, BackgroundUpdateStore
)
self._invalidate_cache_and_stream(
+ txn, self.get_room_summary, (room_id,)
+ )
+
+ self._invalidate_cache_and_stream(
txn, self.get_current_state_ids, (room_id,)
)
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 9b4e6d6aa8..8e941198be 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -82,6 +82,41 @@ class RoomMemberWorkerStore(EventsWorkerStore):
return [to_ascii(r[0]) for r in txn]
return self.runInteraction("get_users_in_room", f)
+ @cached(max_entries=100000, iterable=True)
+ def get_room_summary(self, room_id):
+ def f(txn):
+ sql = (
+ "SELECT m.user_id, m.membership, m.event_id FROM room_memberships as m"
+ " INNER JOIN current_state_events as c"
+ " ON m.event_id = c.event_id "
+ " AND m.room_id = c.room_id "
+ " AND m.user_id = c.state_key"
+ " WHERE c.type = 'm.room.member' AND c.room_id = ? limit ?"
+ )
+
+ txn.execute(sql, (room_id, 5))
+ res = {}
+ for r in txn:
+ summary = res.setdefault(to_ascii[r[1]], {})
+ summary['users'].append((to_ascii(r[0]), to_ascii(r[2])))
+
+ sql = (
+ "SELECT count(*) FROM room_memberships as m"
+ " INNER JOIN current_state_events as c"
+ " ON m.event_id = c.event_id "
+ " AND m.room_id = c.room_id "
+ " AND m.user_id = c.state_key"
+ " WHERE c.type = 'm.room.member' AND c.room_id = ? group by m.membership"
+ )
+
+ txn.execute(sql, (room_id, 5))
+ for r in txn:
+ summary['count'] = r[0]
+
+ return res
+
+ return self.runInteraction("get_room_summary", f)
+
@cached()
def get_invited_rooms_for_user(self, user_id):
""" Get all the rooms the user is invited to
|