Skip to content

Commit f043033

Browse files
committed
use rest_get_paginated_async in api_client instead
1 parent 76ba272 commit f043033

File tree

1 file changed

+1
-32
lines changed

1 file changed

+1
-32
lines changed

synapseclient/client.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from copy import deepcopy
3333
from dataclasses import is_dataclass
3434
from http.client import HTTPResponse
35-
from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union
35+
from typing import Any, Dict, List, Optional, Tuple, Union
3636

3737
import asyncio_atexit
3838
import httpx
@@ -9465,37 +9465,6 @@ async def rest_delete_async(
94659465
**kwargs,
94669466
)
94679467

9468-
async def rest_get_paginated_async(
9469-
self, uri: str, limit: int = 20, offset: int = 0
9470-
) -> AsyncGenerator[Dict[str, Any], None]:
9471-
"""
9472-
Get paginated results asynchronously
9473-
9474-
Arguments:
9475-
uri: A URI that returns paginated results
9476-
limit: How many records should be returned per request
9477-
offset: At what record offset from the first should iteration start
9478-
9479-
Returns:
9480-
A generator over paginated results
9481-
9482-
The limit parameter is set at 20 by default. Using a larger limit results in fewer calls to the service, but if
9483-
responses are large enough to be a burden on the service they may be truncated.
9484-
"""
9485-
prev_num_results = sys.maxsize
9486-
while prev_num_results > 0:
9487-
params = {"offset": offset, "limit": limit}
9488-
page = await self.rest_get_async(
9489-
uri=uri,
9490-
params=params,
9491-
)
9492-
results = page["results"] if "results" in page else page["children"]
9493-
prev_num_results = len(results)
9494-
9495-
for result in results:
9496-
offset += 1
9497-
yield result
9498-
94999468

95009469
async def async_request_hook_httpx(span: Span, request: httpx.Request) -> None:
95019470
"""Hook used to encapsulate a span for this library. The request hook is called

0 commit comments

Comments
 (0)