From 3ecaabc7fd8a1a461c319248a94617cf24dd4070 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 9 Mar 2016 15:45:34 +0000 Subject: [PATCH 1/3] Use topological orders for initial sync timeline --- synapse/storage/stream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index 8908d5b5d..613b54cd1 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -217,8 +217,8 @@ class StreamStore(SQLBaseStore): " room_id = ?" " AND not outlier" " AND stream_ordering <= ?" - " ORDER BY stream_ordering %s LIMIT ?" - ) % (order,) + " ORDER BY topological_ordering %s, stream_ordering %s LIMIT ?" + ) % (order, order,) txn.execute(sql, (room_id, to_id, limit)) rows = self.cursor_to_dict(txn) From af2fe6110c6e249ce0c679ca39bb67d2c16c59c3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 9 Mar 2016 16:11:53 +0000 Subject: [PATCH 2/3] Return the correct token form --- synapse/storage/stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index 613b54cd1..c9f70a08a 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -232,7 +232,7 @@ class StreamStore(SQLBaseStore): get_prev_content=True ) - self._set_before_and_after(ret, rows, topo_order=False) + self._set_before_and_after(ret, rows, topo_order=from_id is None) if order.lower() == "desc": ret.reverse() From 8a88684736efcb6792d17249e2976caefe00ee3d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 9 Mar 2016 16:51:22 +0000 Subject: [PATCH 3/3] Add comment --- synapse/storage/stream.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index c9f70a08a..7f4a82752 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -184,6 +184,9 @@ class StreamStore(SQLBaseStore): @defer.inlineCallbacks def get_room_events_stream_for_room(self, room_id, from_key, to_key, limit=0, order='DESC'): + # Note: If from_key is None then we return in topological order. This + # is because in that case we're using this as a "get the last few messages + # in a room" function, rather than "get new messages since last sync" if from_key is not None: from_id = RoomStreamToken.parse_stream_token(from_key).stream else: