Fixup
2 files changed, 13 insertions, 7 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py
index 893f954ce9..cbaad11a61 100644
--- a/synapse/handlers/sliding_sync.py
+++ b/synapse/handlers/sliding_sync.py
@@ -958,12 +958,18 @@ class SlidingSyncHandler:
# Filter by room type (space vs room, etc). A room must match one of the types
# provided in the list. `None` is a valid type for rooms which do not have a
# room type.
- if False and (filters.room_types is not None or filters.not_room_types is not None):
+ if False and (
+ filters.room_types is not None or filters.not_room_types is not None
+ ):
# Make a copy so we don't run into an error: `Set changed size during
# iteration`, when we filter out and remove items
for room_id in filtered_room_id_set.copy():
- create_event = await self.store.get_create_event_for_room(room_id)
- room_type = create_event.content.get(EventContentFields.ROOM_TYPE)
+ try:
+ create_event = await self.store.get_create_event_for_room(room_id)
+ room_type = create_event.content.get(EventContentFields.ROOM_TYPE)
+ except:
+ room_type = None
+
if (
filters.room_types is not None
and room_type not in filters.room_types
diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py
index 0a2db74401..5ab0fbc5d9 100644
--- a/synapse/storage/databases/main/stream.py
+++ b/synapse/storage/databases/main/stream.py
@@ -1195,12 +1195,12 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
self.database_engine, "room_id", batch
)
sql = f"""
- SELECT room_id, MAX(stream_ordering) FROM events
- WHERE {clause}
- GROUP BY room_id
+ SELECT DISTINCT ON (room_id) room_id, stream_ordering FROM events
+ WHERE {clause} AND stream_ordering IS NOT NULL
+ ORDER BY room_id, stream_ordering DESC
"""
- txn.execute(sql, (args,))
+ txn.execute(sql, args)
return {room_id: stream_ordering for room_id, stream_ordering in txn}
|