summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/data_stores/main/stream.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/synapse/storage/data_stores/main/stream.py b/synapse/storage/data_stores/main/stream.py
index 9fa5e1f203..451f38296b 100644
--- a/synapse/storage/data_stores/main/stream.py
+++ b/synapse/storage/data_stores/main/stream.py
@@ -580,9 +580,12 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
             " FROM events"
             " WHERE room_id = ? AND stream_ordering %s ?"
             " AND NOT outlier"
-            " ORDER BY stream_ordering"
+            " ORDER BY stream_ordering %s"
             " LIMIT 1"
-        ) % ("<=" if dir == "b" else ">=",)
+        ) % (
+            "<=" if dir == "b" else ">=",
+            "DESC" if dir == "b" else "ASC",
+        )
         txn.execute(sql, (room_id, stream_ordering))
         return txn.fetchone()