diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2022-10-14 08:30:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-14 12:30:05 +0000 |
commit | 126a15794c95002560709283640ad412636b29b8 (patch) | |
tree | dca3e2380f4bec49b5dcff4407bc6405eef05692 /synapse/streams | |
parent | Set LD_PRELOAD to load jemalloc in Dockerfile-workers. (#14182) (diff) | |
download | synapse-126a15794c95002560709283640ad412636b29b8.tar.xz |
Do not allow a None-limit on PaginationConfig. (#14146)
The callers either set a default limit or manually handle a None-limit later on (by setting a default value). Update the callers to always instantiate PaginationConfig with a default limit and then assume the limit is non-None.
Diffstat (limited to 'synapse/streams')
-rw-r--r-- | synapse/streams/__init__.py | 2 | ||||
-rw-r--r-- | synapse/streams/config.py | 12 |
2 files changed, 6 insertions, 8 deletions
diff --git a/synapse/streams/__init__.py b/synapse/streams/__init__.py index 806b671305..2dcd43d0a2 100644 --- a/synapse/streams/__init__.py +++ b/synapse/streams/__init__.py @@ -27,7 +27,7 @@ class EventSource(Generic[K, R]): self, user: UserID, from_key: K, - limit: Optional[int], + limit: int, room_ids: Collection[str], is_guest: bool, explicit_room_id: Optional[str] = None, diff --git a/synapse/streams/config.py b/synapse/streams/config.py index f6f7bf3d8b..6df2de919c 100644 --- a/synapse/streams/config.py +++ b/synapse/streams/config.py @@ -35,14 +35,14 @@ class PaginationConfig: from_token: Optional[StreamToken] to_token: Optional[StreamToken] direction: str - limit: Optional[int] + limit: int @classmethod async def from_request( cls, store: "DataStore", request: SynapseRequest, - default_limit: Optional[int] = None, + default_limit: int, default_dir: str = "f", ) -> "PaginationConfig": direction = parse_string( @@ -69,12 +69,10 @@ class PaginationConfig: raise SynapseError(400, "'to' parameter is invalid") limit = parse_integer(request, "limit", default=default_limit) + if limit < 0: + raise SynapseError(400, "Limit must be 0 or above") - if limit: - if limit < 0: - raise SynapseError(400, "Limit must be 0 or above") - - limit = min(int(limit), MAX_LIMIT) + limit = min(limit, MAX_LIMIT) try: return PaginationConfig(from_tok, to_tok, direction, limit) |