Skip to content

Commit 20cd662

Browse files
author
Daniel Bush
committed
feat(SYPL-5699): use record limit
1 parent c41683e commit 20cd662

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

sypht/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33

44
def fetch_all_pages(
5-
name: str, fetch_page: Callable[..., List[Any]], page_limit=1000
5+
name: str, fetch_page: Callable[..., List[Any]], rec_limit=20000
66
) -> Callable[..., Iterator[List[Any]]]:
77
"""Returns an iterator that calls fetch_page with an offset that we increment by the number of pages fetched. Stop if page returns empty list."""
88

99
def fetch_all_pages(*args, **kwargs) -> Iterator[List[Any]]:
1010
page_count = 0
11+
recs = 0
1112
while True:
1213
page_count += 1
13-
if page_count > page_limit:
14+
if recs > rec_limit:
1415
# Don't want to DOS ourselves...
1516
raise Exception(
16-
f"fetch_all_pages({name}): fetched more than {page_limit} pages. Consider using a date range to reduce the number of pages fetched."
17+
f"fetch_all_pages({name}): fetched more than {rec_limit} items. Consider using adding or adjusting a filter to reduce the number of items fetched."
1718
)
1819
try:
1920
result = fetch_page(
@@ -27,6 +28,7 @@ def fetch_all_pages(*args, **kwargs) -> Iterator[List[Any]]:
2728
) from err
2829
if not result:
2930
break
31+
recs += len(result)
3032
yield result
3133

3234
return fetch_all_pages

tests/tests_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def never_ending(*args, **kwargs):
6161
results += page
6262

6363
# assert
64-
assert "fetched more than 1000 pages" in str(exc_info)
64+
assert "fetched more than 20000 items" in str(exc_info)
6565

6666

6767
def test_fetch_all_pages_handle_error():

0 commit comments

Comments
 (0)