Skip to content

Commit

Permalink
Refactor with more efficient queries
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed Jun 17, 2024
1 parent 21b6ba7 commit a363184
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
30 changes: 15 additions & 15 deletions aries_cloudagent/revocation/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,31 @@ async def get_or_create_active_registry(
pass

async with self._profile.session() as session:
rev_reg_records = await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id
full_registries = await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id, None, IssuerRevRegRecord.STATE_FULL, 1
)
full_registries = [
rev
for rev in rev_reg_records
if rev.state == IssuerRevRegRecord.STATE_FULL
]

# all registries are full, create a new one
if len(full_registries) == len(rev_reg_records):
if not full_registries:
# Use any registry to get max cred num
any_registry = (
await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id, limit=1
)
)[0]
await self.init_issuer_registry(
cred_def_id,
max_cred_num=rev_reg_records[0].max_cred_num,
max_cred_num=any_registry.max_cred_num,
)
# if there is a posted registry, activate oldest
else:
posted_registries = sorted(
[
rev
for rev in rev_reg_records
if rev.state == IssuerRevRegRecord.STATE_POSTED
]
posted_registries = await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id, IssuerRevRegRecord.STATE_POSTED, None, None
)
if posted_registries:
posted_registries = sorted(
posted_registries, key=lambda r: r.created_at
)
await self._set_registry_status(
posted_registries[0].revoc_reg_id,
IssuerRevRegRecord.STATE_ACTIVE,
Expand Down
15 changes: 13 additions & 2 deletions aries_cloudagent/revocation/models/issuer_rev_reg_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,12 @@ def get_registry(self) -> RevocationRegistry:

@classmethod
async def query_by_cred_def_id(
cls, session: ProfileSession, cred_def_id: str, state: str = None, limit=None
cls,
session: ProfileSession,
cred_def_id: str,
state: str = None,
negative_state: str = None,
limit=None,
) -> Sequence["IssuerRevRegRecord"]:
"""Retrieve issuer revocation registry records by credential definition ID.
Expand All @@ -539,7 +544,13 @@ async def query_by_cred_def_id(
(("cred_def_id", cred_def_id), ("state", state)),
)
)
return await cls.query(session, tag_filter, limit=limit)
return await cls.query(
session,
tag_filter,
post_filter_positive={"state": state} if state else None,
post_filter_negative={"state": negative_state} if negative_state else None,
limit=limit,
)

@classmethod
async def query_by_pending(
Expand Down

0 comments on commit a363184

Please sign in to comment.