summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-08-18 10:49:23 +0100
committerErik Johnston <erik@matrix.org>2015-08-18 10:49:23 +0100
commitcfc503681f3febbd80faeda0da4134b98bcbcbbc (patch)
tree8da84c50706d7c4593b805dd0d1fe48bad727551 /synapse/storage
parentAdd index receipts_linearized_room_stream (diff)
downloadsynapse-cfc503681f3febbd80faeda0da4134b98bcbcbbc.tar.xz
Comments
Diffstat (limited to '')
-rw-r--r--synapse/storage/receipts.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/synapse/storage/receipts.py b/synapse/storage/receipts.py
index 46c06e42b1..0ed9f45ecd 100644
--- a/synapse/storage/receipts.py
+++ b/synapse/storage/receipts.py
@@ -158,15 +158,25 @@ class ReceiptsStore(SQLBaseStore):
 
         results = {}
         for row in txn_results:
-            results.setdefault(row["room_id"], {
+            # We want a single event per room, since we want to batch the
+            # receipts by room, event and type.
+            room_event = results.setdefault(row["room_id"], {
                 "type": "m.receipt",
                 "room_id": row["room_id"],
                 "content": {},
-            })["content"].setdefault(
+            })
+
+            # The content is of the form:
+            # {"$foo:bar": { "read": { "@user:host": <receipt> }, .. }, .. }
+            event_id = room_event["content"].setdefault(
                 row["event_id"], {}
-            ).setdefault(
+            )
+
+            receipt_type = event_id.setdefault(
                 row["receipt_type"], {}
-            )[row["user_id"]] = json.loads(row["data"])
+            )
+
+            receipt_type[row["user_id"]] = json.loads(row["data"])
 
         results = {
             room_id: [results[room_id]] if room_id in results else []