diff options
author | Jacek KuĊnierz <kusnierz@protonmail.com> | 2022-05-30 22:03:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-30 21:03:52 +0100 |
commit | c4f548e05d9a1858787d3a0883a5393d315473d8 (patch) | |
tree | c34b68772954200b38c5dbc6c2b95e5b2d06047e /synapse/handlers/pagination.py | |
parent | Document the Synapse version of a new module API method (#12917) (diff) | |
download | synapse-c4f548e05d9a1858787d3a0883a5393d315473d8.tar.xz |
Don't return `end` from `/messages` if there are no more events (#12903)
Signed-off-by: Jacek Kusnierz <jacek.kusnierz@tum.de>
Diffstat (limited to 'synapse/handlers/pagination.py')
-rw-r--r-- | synapse/handlers/pagination.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py index 6f4820c240..35afe6b855 100644 --- a/synapse/handlers/pagination.py +++ b/synapse/handlers/pagination.py @@ -515,14 +515,25 @@ class PaginationHandler: next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key) - if events: - if event_filter: - events = await event_filter.filter(events) + # if no events are returned from pagination, that implies + # we have reached the end of the available events. + # In that case we do not return end, to tell the client + # there is no need for further queries. + if not events: + return { + "chunk": [], + "start": await from_token.to_string(self.store), + } - events = await filter_events_for_client( - self.storage, user_id, events, is_peeking=(member_event_id is None) - ) + if event_filter: + events = await event_filter.filter(events) + + events = await filter_events_for_client( + self.storage, user_id, events, is_peeking=(member_event_id is None) + ) + # if after the filter applied there are no more events + # return immediately - but there might be more in next_token batch if not events: return { "chunk": [], |