Skip to content

Commit 2d5464e

Browse files
Refactor OSFStorageProvider to enhance pagination handling and limit parameter for metadata retrieval
1 parent cb27c62 commit 2d5464e

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

waterbutler/providers/osfstorage/provider.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ async def zip(self, path: wb_path.WaterButlerPath, **kwargs) -> asyncio.StreamRe
322322
:param path: ( :class:`.WaterButlerPath` ) The folder to compress
323323
"""
324324
kwargs['minimal'] = True
325+
kwargs['limit'] = None
325326

326327
return streams.ZipStreamReader(utils.ZipStreamGeneratorPaginated(self, path, **kwargs)) # type: ignore
327328

@@ -530,26 +531,17 @@ async def iter_children_pages(self, path, **kwargs):
530531
'children',
531532
user_id=self.auth.get('id'),
532533
minimal=kwargs.get('minimal'),
533-
limit=kwargs.get('limit', 5),
534+
limit=kwargs.get('limit'),
534535
orm=True
535536
)
536537

537-
page, next_url = await self._fetch_metadata_page(url, path, **kwargs)
538538
while True:
539-
next_task = None
540-
541-
if next_url:
542-
next_task = asyncio.create_task(
543-
self._fetch_metadata_page(next_url, path, **kwargs)
544-
)
545-
539+
page, url = await self._fetch_metadata_page(url, path, **kwargs)
546540
yield page
547541

548-
if next_task is None:
542+
if not url:
549543
break
550544

551-
page, next_url = await next_task
552-
553545
# ========== private ==========
554546

555547
async def _item_metadata(self, path, revision=None):
@@ -584,18 +576,20 @@ async def _fetch_metadata_page(self, url, path, **kwargs):
584576
)
585577
resp_json = await resp.json()
586578

587-
if resp_json:
579+
if kwargs.get('limit') and len(resp_json) < kwargs.get('limit'):
580+
next_url = None
581+
elif not kwargs.get('limit'):
582+
next_url = None
583+
else:
588584
next_url = self.build_url(
589585
path.identifier,
590586
'children',
591587
user_id=self.auth.get('id'),
592588
minimal=kwargs.get('minimal'),
593-
limit=kwargs.get('limit', 5),
589+
limit=kwargs.get('limit'),
594590
after=resp_json[-1]['id'] if resp_json else None,
595591
orm=True
596592
)
597-
else:
598-
return [], None
599593
ret = []
600594
for item in resp_json:
601595
if item['kind'] == 'folder':

0 commit comments

Comments
 (0)