Merge pull request #497 from matrix-org/erikj/max_limit

Clamp pagination limits to at most 1000
This commit is contained in:
Erik Johnston 2016-01-14 16:28:52 +00:00
commit a50013fd99
1 changed files with 5 additions and 2 deletions

View File

@ -22,6 +22,9 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
MAX_LIMIT = 1000
class SourcePaginationConfig(object): class SourcePaginationConfig(object):
"""A configuration object which stores pagination parameters for a """A configuration object which stores pagination parameters for a
@ -32,7 +35,7 @@ class SourcePaginationConfig(object):
self.from_key = from_key self.from_key = from_key
self.to_key = to_key self.to_key = to_key
self.direction = 'f' if direction == 'f' else 'b' self.direction = 'f' if direction == 'f' else 'b'
self.limit = int(limit) if limit is not None else None self.limit = min(int(limit), MAX_LIMIT) if limit is not None else None
def __repr__(self): def __repr__(self):
return ( return (
@ -49,7 +52,7 @@ class PaginationConfig(object):
self.from_token = from_token self.from_token = from_token
self.to_token = to_token self.to_token = to_token
self.direction = 'f' if direction == 'f' else 'b' self.direction = 'f' if direction == 'f' else 'b'
self.limit = int(limit) if limit is not None else None self.limit = min(int(limit), MAX_LIMIT) if limit is not None else None
@classmethod @classmethod
def from_request(cls, request, raise_invalid_params=True, def from_request(cls, request, raise_invalid_params=True,