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

Don't support limitless pagination #3265

Merged
merged 2 commits into from
May 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions synapse/storage/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ def _paginate_room_events_txn(self, txn, room_id, from_token, to_token=None,
results to only those before
direction(char): Either 'b' or 'f' to indicate whether we are
paginating forwards or backwards from `from_key`.
limit (int): The maximum number of events to return. Zero or less
means no limit.
limit (int): The maximum number of events to return.
event_filter (Filter|None): If provided filters the events to
those that match the filter.

Expand All @@ -694,6 +693,9 @@ def _paginate_room_events_txn(self, txn, room_id, from_token, to_token=None,
as a list of _EventDictReturn and a token that points to the end
of the result set.
"""

assert int(limit) >= 0

# Tokens really represent positions between elements, but we use
# the convention of pointing to the event before the gap. Hence
# we have a bit of asymmetry when it comes to equalities.
Expand Down Expand Up @@ -723,22 +725,17 @@ def _paginate_room_events_txn(self, txn, room_id, from_token, to_token=None,
bounds += " AND " + filter_clause
args.extend(filter_args)

if int(limit) > 0:
args.append(int(limit))
limit_str = " LIMIT ?"
else:
limit_str = ""
args.append(int(limit))

sql = (
"SELECT event_id, topological_ordering, stream_ordering"
" FROM events"
" WHERE outlier = ? AND room_id = ? AND %(bounds)s"
" ORDER BY topological_ordering %(order)s,"
" stream_ordering %(order)s %(limit)s"
" stream_ordering %(order)s LIMIT ?"
) % {
"bounds": bounds,
"order": order,
"limit": limit_str
}

txn.execute(sql, args)
Expand Down