summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-12 10:28:10 +0100
committerErik Johnston <erik@matrix.org>2015-05-12 10:28:10 +0100
commit4df11b503957a74a948150950da49574c21887bf (patch)
treec389d0586c5e9cc15a4cb0973f00a74c0ce989db /synapse/storage/stream.py
parentInitial hack at wiring together pagination and backfill (diff)
downloadsynapse-4df11b503957a74a948150950da49574c21887bf.tar.xz
Make get_current_token accept a direction parameter, which tells whether the source whether we want a token for going 'forwards' or 'backwards'
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index b03fc67f71..8045e17fd7 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -364,9 +364,25 @@ class StreamStore(SQLBaseStore):
         )
 
     @defer.inlineCallbacks
-    def get_room_events_max_id(self):
+    def get_room_events_max_id(self, direction='f'):
         token = yield self._stream_id_gen.get_max_token(self)
-        defer.returnValue("s%d" % (token,))
+        if direction != 'b':
+            defer.returnValue("s%d" % (token,))
+        else:
+            topo = yield self.runInteraction(
+                "_get_max_topological_txn", self._get_max_topological_txn
+            )
+            defer.returnValue("t%d-%d" % (topo, token))
+
+    def _get_max_topological_txn(self, txn):
+        txn.execute(
+            "SELECT MAX(topological_ordering) FROM events"
+            " WHERE outlier = ?",
+            (False,)
+        )
+
+        rows = txn.fetchall()
+        return rows[0][0] if rows else 0
 
     @defer.inlineCallbacks
     def _get_min_token(self):