summary refs log tree commit diff
path: root/synapse/storage/data_stores
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-01-03 16:09:24 +0000
committerRichard van der Hoff <richard@matrix.org>2020-01-06 13:45:33 +0000
commit15720092ac7a1af57dde7018a8872d93bbb9d36b (patch)
tree3069d06c4991adec312310a5153ff837a1d5b457 /synapse/storage/data_stores
parentrename get_prev_events_for_room to get_prev_events_and_hashes_for_room (diff)
downloadsynapse-15720092ac7a1af57dde7018a8872d93bbb9d36b.tar.xz
replace get_prev_events_and_hashes_for_room with get_prev_events_for_room in create_new_client_event
Diffstat (limited to 'synapse/storage/data_stores')
-rw-r--r--synapse/storage/data_stores/main/event_federation.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/synapse/storage/data_stores/main/event_federation.py b/synapse/storage/data_stores/main/event_federation.py
index 266fc9715f..88e6489576 100644
--- a/synapse/storage/data_stores/main/event_federation.py
+++ b/synapse/storage/data_stores/main/event_federation.py
@@ -177,6 +177,41 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas
 
         return res
 
+    def get_prev_events_for_room(self, room_id: str):
+        """
+        Gets a subset of the current forward extremities in the given room.
+
+        Limits the result to 10 extremities, so that we can avoid creating
+        events which refer to hundreds of prev_events.
+
+        Args:
+            room_id (str): room_id
+
+        Returns:
+            Deferred[List[str]]: the event ids of the forward extremites
+
+        """
+
+        return self.db.runInteraction(
+            "get_prev_events_for_room", self._get_prev_events_for_room_txn, room_id
+        )
+
+    def _get_prev_events_for_room_txn(self, txn, room_id: str):
+        # we just use the 10 newest events. Older events will become
+        # prev_events of future events.
+
+        sql = """
+            SELECT e.event_id FROM event_forward_extremities AS f
+            INNER JOIN events AS e USING (event_id)
+            WHERE f.room_id = ?
+            ORDER BY e.depth DESC
+            LIMIT 10
+        """
+
+        txn.execute(sql, (room_id,))
+
+        return [row[0] for row in txn]
+
     def get_latest_event_ids_and_hashes_in_room(self, room_id):
         """
         Gets the current forward extremities in the given room