|
40 | 40 | from openfga_sdk.models.write_request import WriteRequest |
41 | 41 | from openfga_sdk.validation import is_well_formed_ulid_string |
42 | 42 |
|
43 | | -import time |
44 | 43 | import uuid |
45 | 44 | from typing import List |
| 45 | +from concurrent.futures import ThreadPoolExecutor |
46 | 46 |
|
47 | 47 | CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method" |
48 | 48 | CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id" |
@@ -543,12 +543,16 @@ def batch_check(self, body: List[ClientCheckRequest], options: dict[str, str] = |
543 | 543 | max_parallel_requests = 10 |
544 | 544 | if options is not None and "max_parallel_requests" in options: |
545 | 545 | max_parallel_requests = options["max_parallel_requests"] |
546 | | - # Break the batch into chunks |
547 | | - request_batches = _chuck_array(body, max_parallel_requests) |
| 546 | + |
548 | 547 | batch_check_response = [] |
549 | | - for request_batch in request_batches: |
550 | | - response = [self._single_batch_check(i, options) for i in request_batch] |
551 | | - batch_check_response.extend(response) |
| 548 | + |
| 549 | + def single_batch_check(request): |
| 550 | + return self._single_batch_check(request, options) |
| 551 | + |
| 552 | + with ThreadPoolExecutor(max_workers=max_parallel_requests) as executor: |
| 553 | + for response in executor.map(single_batch_check, body): |
| 554 | + batch_check_response.append(response) |
| 555 | + |
552 | 556 | return batch_check_response |
553 | 557 |
|
554 | 558 | def expand(self, body: ClientExpandRequest, options: dict[str, str] = None): # noqa: E501 |
|
0 commit comments