Skip to content

Commit

Permalink
🎨 call scan on profile.opened.store
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <ff137@proton.me>
  • Loading branch information
ff137 committed May 31, 2024
1 parent 83b48f6 commit a2d98ef
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 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 @@ -187,7 +187,7 @@ async def find_paginated_records(
"""
for_update = bool(options and options.get("forUpdate"))
results = []
async for row in self._session.store.scan(
async for row in self._session.profile.opened.store.scan(
type_filter, tag_query, limit=limit, offset=offset, for_update=for_update
):
results += (
Expand Down Expand Up @@ -338,11 +338,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 @@ -353,11 +356,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 @@ -383,14 +387,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 a2d98ef

Please sign in to comment.