Skip to content

Commit

Permalink
fix: respect small page[size] when streaming search results
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Jan 27, 2025
1 parent 4e52c47 commit 1ce485e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trove/trovesearch/page_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def bounded_page_size(self) -> int:
else int(self.page_size)
)

@property
def is_complete_page(self) -> bool:
return self.bounded_page_size == self.page_size

def as_queryparam_value(self) -> str:
_cls_key = _PageCursorTypes(type(self)).name
_as_json = json.dumps([_cls_key, *dataclasses.astuple(self)])
Expand Down Expand Up @@ -85,7 +89,7 @@ class OffsetCursor(PageCursor):
def is_valid(self) -> bool:
_end_offset = (
self.total_count
if self.bounded_page_size == self.page_size
if self.is_complete_page
else min(self.total_count, self.page_size)
)
return (
Expand Down
2 changes: 2 additions & 0 deletions trove/trovesearch/search_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __post_init__(self):
return _page

def get_next_streaming_handle(self) -> typing.Self | None:
if self.cursor.is_complete_page:
return None
_next_cursor = self.cursor.next_cursor()
if (_next_cursor is not None) and (self.handler is not None):
assert isinstance(self.search_params, CardsearchParams)
Expand Down

0 comments on commit 1ce485e

Please sign in to comment.