Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit c4f548e

Browse files
authored
Don't return end from /messages if there are no more events (#12903)
Signed-off-by: Jacek Kusnierz <jacek.kusnierz@tum.de>
1 parent cd9fc05 commit c4f548e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

changelog.d/12903.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug which caused the `/messages` endpoint to return an incorrect `end` attribute when there were no more events. Contributed by @Vetchu.

synapse/handlers/pagination.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,25 @@ async def get_messages(
515515

516516
next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key)
517517

518-
if events:
519-
if event_filter:
520-
events = await event_filter.filter(events)
518+
# if no events are returned from pagination, that implies
519+
# we have reached the end of the available events.
520+
# In that case we do not return end, to tell the client
521+
# there is no need for further queries.
522+
if not events:
523+
return {
524+
"chunk": [],
525+
"start": await from_token.to_string(self.store),
526+
}
521527

522-
events = await filter_events_for_client(
523-
self.storage, user_id, events, is_peeking=(member_event_id is None)
524-
)
528+
if event_filter:
529+
events = await event_filter.filter(events)
530+
531+
events = await filter_events_for_client(
532+
self.storage, user_id, events, is_peeking=(member_event_id is None)
533+
)
525534

535+
# if after the filter applied there are no more events
536+
# return immediately - but there might be more in next_token batch
526537
if not events:
527538
return {
528539
"chunk": [],

0 commit comments

Comments
 (0)