mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-26 11:36:03 +03:00
Give the correct next event when the message timestamps are the same - MSC3030 (#13658)
Discovered while working on https://github.com/matrix-org/synapse/pull/13589 and I had all the messages at the same timestamp in the tests. Part of https://github.com/matrix-org/matrix-spec-proposals/pull/3030 Complement tests: https://github.com/matrix-org/complement/pull/457
This commit is contained in:
parent
20c76cecb9
commit
92c5817e34
2 changed files with 11 additions and 2 deletions
1
changelog.d/13658.bugfix
Normal file
1
changelog.d/13658.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix MSC3030 `/timestamp_to_event` endpoint to return the correct next event when the events have the same timestamp.
|
|
@ -2111,7 +2111,14 @@ class EventsWorkerStore(SQLBaseStore):
|
||||||
AND room_id = ?
|
AND room_id = ?
|
||||||
/* Make sure event is not rejected */
|
/* Make sure event is not rejected */
|
||||||
AND rejections.event_id IS NULL
|
AND rejections.event_id IS NULL
|
||||||
ORDER BY origin_server_ts %s
|
/**
|
||||||
|
* First sort by the message timestamp. If the message timestamps are the
|
||||||
|
* same, we want the message that logically comes "next" (before/after
|
||||||
|
* the given timestamp) based on the DAG and its topological order (`depth`).
|
||||||
|
* Finally, we can tie-break based on when it was received on the server
|
||||||
|
* (`stream_ordering`).
|
||||||
|
*/
|
||||||
|
ORDER BY origin_server_ts %s, depth %s, stream_ordering %s
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -2130,7 +2137,8 @@ class EventsWorkerStore(SQLBaseStore):
|
||||||
order = "ASC"
|
order = "ASC"
|
||||||
|
|
||||||
txn.execute(
|
txn.execute(
|
||||||
sql_template % (comparison_operator, order), (timestamp, room_id)
|
sql_template % (comparison_operator, order, order, order),
|
||||||
|
(timestamp, room_id),
|
||||||
)
|
)
|
||||||
row = txn.fetchone()
|
row = txn.fetchone()
|
||||||
if row:
|
if row:
|
||||||
|
|
Loading…
Reference in a new issue