Skip to content

Commit

Permalink
✨ add optional limit and offset to AskarStorageSearchSession.fetch
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <ff137@proton.me>
  • Loading branch information
ff137 committed Jun 3, 2024
1 parent 391b2c5 commit 7d6c13d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions aries_cloudagent/storage/askar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Aries-Askar implementation of BaseStorage interface."""

from typing import Mapping, Sequence
from typing import Mapping, Optional, Sequence

from aries_askar import AskarError, AskarErrorCode, Session

Expand Down Expand Up @@ -340,11 +340,14 @@ async def __anext__(self):
tags=row.tags,
)

async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:
async def fetch(
self, max_count: Optional[int] = None, offset: Optional[int] = None
) -> Sequence[StorageRecord]:
"""Fetch the next list of results from the store.
Args:
max_count: Max number of records to return
offset: The offset to start retrieving records from
Returns:
A list of `StorageRecord` instances
Expand All @@ -355,11 +358,12 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:
"""
if self._done:
raise StorageSearchError("Search query is complete")
await self._open()

limit = max_count or self.page_size
await self._open(limit=limit, offset=offset)

count = 0
ret = []
limit = max_count or self.page_size

while count < limit:
try:
Expand All @@ -385,14 +389,16 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:

return ret

async def _open(self):
async def _open(self, offset: Optional[int] = None, limit: Optional[int] = None):
"""Start the search query."""
if self._scan:
return
try:
self._scan = self._profile.store.scan(
category=self.type_filter,
tag_filter=self.tag_query,
offset=offset,
limit=limit,
profile=self._profile.settings.get("wallet.askar_profile"),
)
except AskarError as err:
Expand Down

0 comments on commit 7d6c13d

Please sign in to comment.