Fix bug /sync returning 404 (#12729)

* Fix bug /sync returning 404

Fixes #12571
This commit is contained in:
Erik Johnston 2022-05-16 12:06:56 +01:00 committed by GitHub
parent efcd899f69
commit 8689230a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

1
changelog.d/12729.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.58.0 where `/sync` would fail if the most recent event in a room was rejected.

View File

@ -743,14 +743,17 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
""" """
def _f(txn: LoggingTransaction) -> Optional[Tuple[int, int, str]]: def _f(txn: LoggingTransaction) -> Optional[Tuple[int, int, str]]:
sql = ( sql = """
"SELECT stream_ordering, topological_ordering, event_id" SELECT stream_ordering, topological_ordering, event_id
" FROM events" FROM events
" WHERE room_id = ? AND stream_ordering <= ?" LEFT JOIN rejections USING (event_id)
" AND NOT outlier" WHERE room_id = ?
" ORDER BY stream_ordering DESC" AND stream_ordering <= ?
" LIMIT 1" AND NOT outlier
) AND rejections.reason IS NULL
ORDER BY stream_ordering DESC
LIMIT 1
"""
txn.execute(sql, (room_id, stream_ordering)) txn.execute(sql, (room_id, stream_ordering))
return cast(Optional[Tuple[int, int, str]], txn.fetchone()) return cast(Optional[Tuple[int, int, str]], txn.fetchone())