Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race mongo #161

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added a localcaching for didDocument
  • Loading branch information
Pratap2018 committed Nov 25, 2024
commit 0e24724664bf0af3b3e6041b8fb4758682b9603c
15 changes: 13 additions & 2 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
} from '../dto/register-credential.dto';
import { getAppVault, getAppMenemonic } from '../../utils/app-vault-service';
import { TxSendModuleService } from 'src/tx-send-module/tx-send-module.service';

import * as NodeCache from 'node-cache';
const myCache = new NodeCache();
@Injectable()
export class CredentialService {
constructor(
Expand Down Expand Up @@ -112,7 +113,16 @@
);
const seed = await this.hidWallet.getSeedFromMnemonic(issuerMnemonic);
const hypersignDid = new HypersignDID();
const { didDocument } = await hypersignDid.resolve({ did: issuerDid });
let didDocument;
if (myCache.has(issuerDid)) {
didDocument = myCache.get(issuerDid);
console.log('Getting from Cache');
} else {
const resp = await hypersignDid.resolve({ did: issuerDid });
didDocument = resp.didDocument;
myCache.set(issuerDid, didDocument);
Logger.log('Setting Cache');
}
const verificationMethod = didDocument.verificationMethod.find(
(vm) => vm.id === verificationMethodId,
);
Expand Down Expand Up @@ -192,6 +202,7 @@
} = await hypersignVC.issue({
credential,
issuerDid,
issuerDidDoc: didDocument,
verificationMethodId,
privateKeyMultibase,
registerCredential: false,
Expand Down Expand Up @@ -417,7 +428,7 @@
'CredentialService',
);

const { wallet, address } = await this.hidWallet.generateWallet(

Check warning on line 431 in src/credential/services/credential.service.ts

View workflow job for this annotation

GitHub Actions / build

'wallet' is assigned a value but never used
appMenemonic,
);
let updatedCredResult;
Expand Down Expand Up @@ -550,7 +561,7 @@
);

const { credentialStatus, namespace } = registerCredentialDto;
const credentialId = credentialStatus.id;

Check warning on line 564 in src/credential/services/credential.service.ts

View workflow job for this annotation

GitHub Actions / build

'credentialId' is assigned a value but never used
const { kmsId } = appDetail;
Logger.log(
'registerCredentialStatus() method: initialising edv service',
Expand All @@ -568,7 +579,7 @@

delete credentialStatus['proof'];

const { wallet, address } = await this.hidWallet.generateWallet(

Check warning on line 582 in src/credential/services/credential.service.ts

View workflow job for this annotation

GitHub Actions / build

'wallet' is assigned a value but never used
appMenemonic,
);
let hypersignVC;
Expand Down
Loading