summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2018-03-06 11:20:23 +0000
committerGitHub <noreply@github.com>2018-03-06 11:20:23 +0000
commitb2932107bb6ccf3e171ead57d51917624f5e017c (patch)
treee968c520f684bd7e82f70de37c32057205997754 /synapse/storage/stream.py
parentMerge pull request #2948 from matrix-org/erikj/kill_as_sync (diff)
parentProvide a means to pass a timestamp to purge_history (diff)
downloadsynapse-b2932107bb6ccf3e171ead57d51917624f5e017c.tar.xz
Merge pull request #2946 from matrix-org/rav/timestamp_to_purge
Implement purge_history by timestamp
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index b78151cd82..2956c3b3e0 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -415,6 +415,33 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
             "get_recent_events_for_room", get_recent_events_for_room_txn
         )
 
+    def get_room_event_after_stream_ordering(self, room_id, stream_ordering):
+        """Gets details of the first event in a room at or after a stream ordering
+
+        Args:
+            room_id (str):
+            stream_ordering (int):
+
+        Returns:
+            Deferred[(int, int, str)]:
+                (stream ordering, topological ordering, event_id)
+        """
+        def _f(txn):
+            sql = (
+                "SELECT stream_ordering, topological_ordering, event_id"
+                " FROM events"
+                " WHERE room_id = ? AND stream_ordering >= ?"
+                " AND NOT outlier"
+                " ORDER BY stream_ordering"
+                " LIMIT 1"
+            )
+            txn.execute(sql, (room_id, stream_ordering, ))
+            return txn.fetchone()
+
+        return self.runInteraction(
+            "get_room_event_after_stream_ordering", _f,
+        )
+
     @defer.inlineCallbacks
     def get_room_events_max_id(self, room_id=None):
         """Returns the current token for rooms stream.