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

Do not allow a None-limit on PaginationConfig #14146

Merged
merged 7 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion synapse/handlers/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def get_new_events(
self,
user: UserID,
from_key: int,
limit: Optional[int],
limit: int,
room_ids: Collection[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
Expand Down
27 changes: 4 additions & 23 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ def __init__(self, hs: "HomeServer"):
self.validator = EventValidator()
self.snapshot_cache: ResponseCache[
Tuple[
str,
Optional[StreamToken],
Optional[StreamToken],
str,
Optional[int],
bool,
bool,
str, Optional[StreamToken], Optional[StreamToken], str, int, bool, bool
]
] = ResponseCache(hs.get_clock(), "initial_sync_cache")
self._event_serializer = hs.get_event_client_serializer()
Expand Down Expand Up @@ -154,11 +148,6 @@ async def _snapshot_all_rooms(

public_room_ids = await self.store.get_public_room_ids()

if pagin_config.limit is not None:
limit = pagin_config.limit
else:
limit = 10

serializer_options = SerializeEventConfig(as_client_event=as_client_event)

async def handle_room(event: RoomsForUser) -> None:
Expand Down Expand Up @@ -210,7 +199,7 @@ async def handle_room(event: RoomsForUser) -> None:
run_in_background(
self.store.get_recent_events_for_room,
event.room_id,
limit=limit,
limit=pagin_config.limit,
end_token=room_end_token,
),
deferred_room_state,
Expand Down Expand Up @@ -360,15 +349,11 @@ async def _room_initial_sync_parted(
member_event_id
)

limit = pagin_config.limit if pagin_config else None
if limit is None:
limit = 10

leave_position = await self.store.get_position_for_event(member_event_id)
stream_token = leave_position.to_room_stream_token()

messages, token = await self.store.get_recent_events_for_room(
room_id, limit=limit, end_token=stream_token
room_id, limit=pagin_config.limit, end_token=stream_token
)

messages = await filter_events_for_client(
Expand Down Expand Up @@ -420,10 +405,6 @@ async def _room_initial_sync_joined(

now_token = self.hs.get_event_sources().get_current_token()

limit = pagin_config.limit if pagin_config else None
if limit is None:
limit = 10

room_members = [
m
for m in current_state.values()
Expand Down Expand Up @@ -467,7 +448,7 @@ async def get_receipts() -> List[JsonDict]:
run_in_background(
self.store.get_recent_events_for_room,
room_id,
limit=limit,
limit=pagin_config.limit,
end_token=now_token.room_key,
),
),
Expand Down
5 changes: 0 additions & 5 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,6 @@ async def get_messages(
# `/messages` should still works with live tokens when manually provided.
assert from_token.room_key.topological is not None

if pagin_config.limit is None:
# This shouldn't happen as we've set a default limit before this
# gets called.
raise Exception("limit not set")

room_token = from_token.room_key

async with self.pagination_lock.read(room_id):
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,9 @@ async def get_new_events(
self,
user: UserID,
from_key: Optional[int],
limit: Optional[int] = None,
# Having a default limit doesn't match the EventSource API, but some
# callers do not provide it. It is unused in this class.
limit: int = 0,
room_ids: Optional[Collection[str]] = None,
is_guest: bool = False,
explicit_room_id: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async def get_new_events(
self,
user: UserID,
from_key: int,
limit: Optional[int],
limit: int,
room_ids: Iterable[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
Expand Down
3 changes: 0 additions & 3 deletions synapse/handlers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ async def get_relations(
if event is None:
raise SynapseError(404, "Unknown parent event.")

# TODO Update pagination config to not allow None limits.
assert pagin_config.limit is not None

# Note that ignored users are not passed into get_relations_for_event
# below. Ignored users are handled in filter_events_for_client (and by
# not passing them in here we should get a better cache hit rate).
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ async def get_new_events(
self,
user: UserID,
from_key: RoomStreamToken,
limit: Optional[int],
limit: int,
room_ids: Collection[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ async def get_new_events(
self,
user: UserID,
from_key: int,
limit: Optional[int],
limit: int,
room_ids: Iterable[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion synapse/streams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def get_new_events(
self,
user: UserID,
from_key: K,
limit: Optional[int],
limit: int,
room_ids: Collection[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion synapse/streams/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PaginationConfig:
from_token: Optional[StreamToken]
to_token: Optional[StreamToken]
direction: str
limit: Optional[int]
limit: int

@classmethod
async def from_request(
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/client/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_set_typing(self) -> None:
self.event_source.get_new_events(
user=UserID.from_string(self.user_id),
from_key=0,
limit=None,
limit=0,
clokep marked this conversation as resolved.
Show resolved Hide resolved
room_ids=[self.room_id],
is_guest=False,
)
Expand Down