|
26 | 26 | to_text, |
27 | 27 | to_tuple, |
28 | 28 | ) |
29 | | -from eth_utils.toolz import ( |
30 | | - concat, |
31 | | -) |
32 | 29 |
|
33 | 30 | from ethpm import ( |
34 | 31 | ASSETS_DIR, |
@@ -217,6 +214,9 @@ def deploy_new_instance(cls, w3): |
217 | 214 | pass |
218 | 215 |
|
219 | 216 |
|
| 217 | +BATCH_SIZE = 100 |
| 218 | + |
| 219 | + |
220 | 220 | class SimpleRegistry(ERC1319Registry): |
221 | 221 | """ |
222 | 222 | This class represents an instance of the `Solidity Reference Registry implementation |
@@ -245,29 +245,34 @@ def _get_package_name(self, package_id: bytes) -> str: |
245 | 245 | @to_tuple |
246 | 246 | def _get_all_package_ids(self) -> Iterable[Tuple[bytes]]: |
247 | 247 | num_packages = self._num_package_ids() |
248 | | - # Logic here b/c Solidity Reference Registry implementation returns ids in reverse order |
249 | | - package_ids = [ |
250 | | - self.registry.functions.getAllPackageIds(index, (index + 4)).call()[0] |
251 | | - for index in range(0, num_packages, 4) |
252 | | - ] |
253 | | - for package_id in concat([x[::-1] for x in package_ids]): |
254 | | - yield package_id |
| 248 | + pointer = 0 |
| 249 | + while pointer < num_packages: |
| 250 | + new_ids, new_pointer = self.registry.functions.getAllPackageIds( |
| 251 | + pointer, |
| 252 | + (pointer + BATCH_SIZE) |
| 253 | + ).call() |
| 254 | + if not new_pointer > pointer: |
| 255 | + break |
| 256 | + yield from reversed(new_ids) |
| 257 | + pointer = new_pointer |
255 | 258 |
|
256 | 259 | def _get_release_id(self, package_name: str, version: str) -> bytes: |
257 | 260 | return self.registry.functions.getReleaseId(package_name, version).call() |
258 | 261 |
|
259 | 262 | @to_tuple |
260 | 263 | def _get_all_release_ids(self, package_name: str) -> Iterable[Tuple[bytes]]: |
261 | 264 | num_releases = self._num_release_ids(package_name) |
262 | | - # Logic here b/c Solidity Reference Registry implementation returns ids in reverse order |
263 | | - release_ids = [ |
264 | | - self.registry.functions.getAllReleaseIds( |
265 | | - package_name, index, (index + 4) |
266 | | - ).call()[0] |
267 | | - for index in range(0, num_releases, 4) |
268 | | - ] |
269 | | - for release_id in concat([x[::-1] for x in release_ids]): |
270 | | - yield release_id |
| 265 | + pointer = 0 |
| 266 | + while pointer < num_releases: |
| 267 | + new_ids, new_pointer = self.registry.functions.getAllReleaseIds( |
| 268 | + package_name, |
| 269 | + pointer, |
| 270 | + (pointer + BATCH_SIZE) |
| 271 | + ).call() |
| 272 | + if not new_pointer > pointer: |
| 273 | + break |
| 274 | + yield from reversed(new_ids) |
| 275 | + pointer = new_pointer |
271 | 276 |
|
272 | 277 | @to_tuple |
273 | 278 | def _get_release_data(self, release_id: bytes) -> Iterable[Tuple[str]]: |
|
0 commit comments