summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2020-01-08 14:23:27 +0000
committerErik Johnston <erik@matrix.org>2020-01-08 14:24:28 +0000
commit187dc6ad0278c12f15cf2300659d5a1e10ef2446 (patch)
tree33fa25962b41754302ec79115933a388276f7d22
parentNewsfile (diff)
downloadsynapse-187dc6ad0278c12f15cf2300659d5a1e10ef2446.tar.xz
Do not rely on streaming events, as media repo doesn't
-rw-r--r--synapse/storage/data_stores/main/room.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/synapse/storage/data_stores/main/room.py b/synapse/storage/data_stores/main/room.py
index 652518049a..0509d9f64d 100644
--- a/synapse/storage/data_stores/main/room.py
+++ b/synapse/storage/data_stores/main/room.py
@@ -448,21 +448,32 @@ class RoomWorkerStore(SQLBaseStore):
         """
         mxc_re = re.compile("^mxc://([^/]+)/([^/#?]+)")
 
-        next_token = self.get_current_events_token() + 1
+        next_token = None
         local_media_mxcs = []
         remote_media_mxcs = []
 
-        while next_token:
-            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))
+        while True:
+            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:
@@ -484,6 +495,9 @@ class RoomWorkerStore(SQLBaseStore):
                         else:
                             remote_media_mxcs.append((hostname, media_id))
 
+            if next_token is None:
+                break
+
         return local_media_mxcs, remote_media_mxcs