From b8687e771cef14ac936bf4c401c83470fae1d8e7 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 1 Jul 2024 21:42:11 -0500 Subject: [PATCH 1/2] Select `to_key if to_key else from_key` See https://github.com/element-hq/synapse/pull/17320#discussion_r1646591886 --- synapse/storage/databases/main/stream.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py index 7e6beb5239..f96032c953 100644 --- a/synapse/storage/databases/main/stream.py +++ b/synapse/storage/databases/main/stream.py @@ -1827,7 +1827,9 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore): and to_key is not None and to_key.is_before_or_eq(from_key) ): - return [], from_key + # Token selection matches what we do in `_paginate_room_events_txn` if there + # are no rows + return [], to_key if to_key else from_key # Or vice-versa, if we're looking backwards and our `from_key` is already before # our `to_key`. elif ( @@ -1835,7 +1837,9 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore): and to_key is not None and from_key.is_before_or_eq(to_key) ): - return [], from_key + # Token selection matches what we do in `_paginate_room_events_txn` if there + # are no rows + return [], to_key if to_key else from_key rows, token = await self.db_pool.runInteraction( "paginate_room_events", From 7c9513ccb1d6e4ab296395fe171318a9a128d052 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 1 Jul 2024 21:49:41 -0500 Subject: [PATCH 2/2] Add missing test description --- tests/handlers/test_sliding_sync.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/handlers/test_sliding_sync.py b/tests/handlers/test_sliding_sync.py index a751fef1df..3d37a696d5 100644 --- a/tests/handlers/test_sliding_sync.py +++ b/tests/handlers/test_sliding_sync.py @@ -1410,7 +1410,8 @@ class GetSyncRoomIdsForUserTestCase(HomeserverTestCase): self, ) -> None: """ - Test that `newly_joined` TODO + Test that even though we're joined before the token range, if we leave and join + within the token range, it's still counted as `newly_joined`. """ user1_id = self.register_user("user1", "pass") user1_tok = self.login(user1_id, "pass")