summary refs log tree commit diff
path: root/synapse/storage/data_stores
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2020-01-08 14:57:45 +0000
committerErik Johnston <erik@matrix.org>2020-01-08 14:57:45 +0000
commitd74054afda9cf7c63c9f74a9b55c02f9df321d6d (patch)
treef01245ab58c73490024ca9f105ad4389642466bc /synapse/storage/data_stores
parentComments (diff)
downloadsynapse-d74054afda9cf7c63c9f74a9b55c02f9df321d6d.tar.xz
Shuffle the code
Diffstat (limited to 'synapse/storage/data_stores')
-rw-r--r--synapse/storage/data_stores/main/room.py41
1 files changed, 16 insertions, 25 deletions
diff --git a/synapse/storage/data_stores/main/room.py b/synapse/storage/data_stores/main/room.py
index 11e93fd668..8636d75030 100644
--- a/synapse/storage/data_stores/main/room.py
+++ b/synapse/storage/data_stores/main/room.py
@@ -448,35 +448,21 @@ class RoomWorkerStore(SQLBaseStore):
         """
         mxc_re = re.compile("^mxc://([^/]+)/([^/#?]+)")
 
-        next_token = None
+        sql = """
+            SELECT stream_ordering, json FROM events
+            JOIN event_json USING (room_id, event_id)
+            WHERE room_id = ?
+                %(where_clause)s
+                AND contains_url = ? AND outlier = ?
+            ORDER BY stream_ordering DESC
+            LIMIT ?
+        """
+        txn.execute(sql % {"where_clause": ""}, (room_id, True, False, 100))
+
         local_media_mxcs = []
         remote_media_mxcs = []
 
         while True:
-            # The first time round we just want to get the most recent
-            # events, then we bound by stream ordering
-            if next_token is None:
-                sql = """
-                    SELECT stream_ordering, json FROM events
-                    JOIN event_json USING (room_id, event_id)
-                    WHERE room_id = ?
-                        AND contains_url = ? AND outlier = ?
-                    ORDER BY stream_ordering DESC
-                    LIMIT ?
-                """
-                txn.execute(sql, (room_id, True, False, 100))
-            else:
-                sql = """
-                    SELECT stream_ordering, json FROM events
-                    JOIN event_json USING (room_id, event_id)
-                    WHERE room_id = ?
-                        AND stream_ordering < ?
-                        AND contains_url = ? AND outlier = ?
-                    ORDER BY stream_ordering DESC
-                    LIMIT ?
-                """
-                txn.execute(sql, (room_id, next_token, True, False, 100))
-
             next_token = None
             for stream_ordering, content_json in txn:
                 next_token = stream_ordering
@@ -501,6 +487,11 @@ class RoomWorkerStore(SQLBaseStore):
                 # We've gone through the whole room, so we're finished.
                 break
 
+            txn.execute(
+                sql % {"where_clause": "AND stream_ordering < ?"},
+                (room_id, next_token, True, False, 100),
+            )
+
         return local_media_mxcs, remote_media_mxcs