Skip to content

Commit

Permalink
Fix fetching v6 assertion first
Browse files Browse the repository at this point in the history
  • Loading branch information
Zvonimir authored and Zvonimir committed Dec 27, 2024
1 parent 727f5e2 commit 7c2db0e
Showing 1 changed file with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,43 +125,50 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {

if (assertionId) {
// DO NOT RUN THIS IF !assertionId
assertionPromise = this.tripleStoreService
.getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId)
.then(async (result) => {
if (!result?.length) {
this.logger.info(
`No V6 assertion found for assertionId: ${assertionId}, falling back to V8 getAssertion`,
);
assertionPromise = (async () => {
let result = null;

if (!isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.PUBLIC,
);
}

const fallbackResult = await this.tripleStoreService.getAssertion(
if (!result?.length) {
// eslint-disable-next-line no-await-in-loop
result = await this.tripleStoreService.getV6Assertion(
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
assertionId,
);
if (result?.length && !isOperationV0) {
notMigrated = true;
}

if (!result?.length && isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.PUBLIC,
);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);

return fallbackResult;
}

if (!isOperationV0) {
notMigrated = true;
}
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);

return result.split('\n').filter((res) => res.length > 0);
});
return typeof result === 'string'
? result.split('\n').filter((res) => res.length > 0)
: result;
})();
} else {
if (!knowledgeAssetId) {
try {
Expand Down

0 comments on commit 7c2db0e

Please sign in to comment.