summary refs log tree commit diff
path: root/synapse/storage/roommember.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-07-18 02:07:36 +0100
committerMatthew Hodgson <matthew@matrix.org>2018-07-18 02:07:36 +0100
commita34061d3329789a4f2e16ec09dbcc9ed5074e346 (patch)
tree9089d6237de734347a8de8afb0ee32879d49aee0 /synapse/storage/roommember.py
parentFix develop because I broke it :( (#3535) (diff)
downloadsynapse-a34061d3329789a4f2e16ec09dbcc9ed5074e346.tar.xz
WIP of tracking per-room and per-user stats
Diffstat (limited to 'synapse/storage/roommember.py')
-rw-r--r--synapse/storage/roommember.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 02a802bed9..1493a881d9 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -83,6 +83,24 @@ class RoomMemberWorkerStore(EventsWorkerStore):
         return self.runInteraction("get_users_in_room", f)
 
     @cached()
+    def get_user_count_in_room(self, room_id, membership):
+        def f(txn):
+            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 = ? AND m.membership = ?"
+            )
+
+            txn.execute(sql, (room_id, membership,))
+            row = txn.fetchone()
+            return row[0]
+
+        return self.runInteraction("get_users_in_room", f)
+
+    @cached()
     def get_invited_rooms_for_user(self, user_id):
         """ Get all the rooms the user is invited to
         Args: