Skip to content

Commit

Permalink
fix(cardano-services): release query runner after query execution
Browse files Browse the repository at this point in the history
  • Loading branch information
mchappell committed May 9, 2024
1 parent 8c13737 commit e1d2de7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
23 changes: 14 additions & 9 deletions packages/cardano-services/src/Asset/TypeOrmNftMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ export class TypeOrmNftMetadataService extends TypeormService implements NftMeta
const assetId = Cardano.AssetId.fromParts(assetInfo.policyId, assetInfo.name);
return this.withDataSource(async (dataSource) => {
const queryRunner = dataSource.createQueryRunner();
const nftMetadataRepository = queryRunner.manager.getRepository(NftMetadataEntity);
let asset: NftMetadataEntity | null;

const asset = await nftMetadataRepository
.findOneBy({
userTokenAsset: { id: assetId }
})
.catch((error) => {
this.logger.error(error);
return null;
});
try {
const nftMetadataRepository = queryRunner.manager.getRepository(NftMetadataEntity);
asset = await nftMetadataRepository
.findOneBy({
userTokenAsset: { id: assetId }
})
.catch((error) => {
this.logger.error(error);
return null;
});
} finally {
await queryRunner.release();
}

if (!asset) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ export class TypeormAssetProvider extends TypeormProvider implements AssetProvid

return this.withDataSource(async (dataSource) => {
const queryRunner = dataSource.createQueryRunner();
const assetRepository = queryRunner.manager.getRepository(AssetEntity);

const asset = await assetRepository.findOneBy({ id: assetId });

if (!asset) throw new ProviderError(ProviderFailure.NotFound, undefined, `Asset not found '${assetId}'`);
const supply = asset.supply!;
let supply: bigint;
try {
const assetRepository = queryRunner.manager.getRepository(AssetEntity);
const asset = await assetRepository.findOneBy({ id: assetId });
if (!asset) throw new ProviderError(ProviderFailure.NotFound, undefined, `Asset not found '${assetId}'`);
supply = asset.supply!;
} finally {
await queryRunner.release();
}

return {
assetId,
Expand Down

0 comments on commit e1d2de7

Please sign in to comment.