mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-17 23:50:09 -04:00
Properly paginate forward in the /relations API. (#13840)
This fixes a bug where the `/relations` API with `dir=f` would skip the first item of each page (except the first page), causing incomplete data to be returned to the client.
This commit is contained in:
parent
1a1abdda42
commit
b7272b73aa
4 changed files with 60 additions and 14 deletions
|
@ -788,6 +788,7 @@ class RelationPaginationTestCase(BaseRelationsTestCase):
|
|||
channel.json_body["chunk"][0],
|
||||
)
|
||||
|
||||
@unittest.override_config({"experimental_features": {"msc3715_enabled": True}})
|
||||
def test_repeated_paginate_relations(self) -> None:
|
||||
"""Test that if we paginate using a limit and tokens then we get the
|
||||
expected events.
|
||||
|
@ -809,7 +810,7 @@ class RelationPaginationTestCase(BaseRelationsTestCase):
|
|||
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?limit=1{from_token}",
|
||||
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?limit=3{from_token}",
|
||||
access_token=self.user_token,
|
||||
)
|
||||
self.assertEqual(200, channel.code, channel.json_body)
|
||||
|
@ -827,6 +828,32 @@ class RelationPaginationTestCase(BaseRelationsTestCase):
|
|||
found_event_ids.reverse()
|
||||
self.assertEqual(found_event_ids, expected_event_ids)
|
||||
|
||||
# Test forward pagination.
|
||||
prev_token = ""
|
||||
found_event_ids = []
|
||||
for _ in range(20):
|
||||
from_token = ""
|
||||
if prev_token:
|
||||
from_token = "&from=" + prev_token
|
||||
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?org.matrix.msc3715.dir=f&limit=3{from_token}",
|
||||
access_token=self.user_token,
|
||||
)
|
||||
self.assertEqual(200, channel.code, channel.json_body)
|
||||
|
||||
found_event_ids.extend(e["event_id"] for e in channel.json_body["chunk"])
|
||||
next_batch = channel.json_body.get("next_batch")
|
||||
|
||||
self.assertNotEqual(prev_token, next_batch)
|
||||
prev_token = next_batch
|
||||
|
||||
if not prev_token:
|
||||
break
|
||||
|
||||
self.assertEqual(found_event_ids, expected_event_ids)
|
||||
|
||||
def test_pagination_from_sync_and_messages(self) -> None:
|
||||
"""Pagination tokens from /sync and /messages can be used to paginate /relations."""
|
||||
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "A")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue