From ab78b1ee8cdcd98ffb3664edca105bcd3af311ec Mon Sep 17 00:00:00 2001 From: Sepehr Ganji Date: Mon, 29 Jan 2024 22:03:08 -0700 Subject: [PATCH] batch headerId in transaction query --- src/context/transactions-repository.ts | 15 +++++++++++++-- src/graphql/resolvers/transaction-resolver.ts | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/context/transactions-repository.ts b/src/context/transactions-repository.ts index 5a53a01..7a882e9 100644 --- a/src/context/transactions-repository.ts +++ b/src/context/transactions-repository.ts @@ -12,6 +12,7 @@ type TransactionFindOptions = FindManyParams & { address?: string; addresses?: string[]; transactionIds?: string[]; + headerIds?: string[]; }; export class TransactionRepository extends BaseRepository { @@ -23,7 +24,7 @@ export class TransactionRepository extends BaseRepository { } public override async find(options: TransactionFindOptions): Promise { - const { minHeight, maxHeight, address, addresses, transactionIds } = options; + const { minHeight, maxHeight, address, addresses, transactionIds, headerIds } = options; const ergoTrees = addresses ? addresses.map((address) => ErgoAddress.fromBase58(address).ergoTree) : []; @@ -65,13 +66,23 @@ export class TransactionRepository extends BaseRepository { filterQuery = filterQuery.andWhere(`${this.alias}.transactionId IN (:...transactionIds)`); } + if (options.where?.headerId && headerIds) { + headerIds.push(options.where.headerId); + delete options.where.headerId; + } + + if (headerIds && headerIds.length > 0) { + filterQuery = filterQuery.andWhere(`${this.alias}.headerId IN (:...headerIds)`); + } + filterQuery = filterQuery.setParameters( removeUndefined({ height: maxHeight, maxHeight, minHeight, ergoTrees, - transactionIds + transactionIds, + headerIds }) ); diff --git a/src/graphql/resolvers/transaction-resolver.ts b/src/graphql/resolvers/transaction-resolver.ts index 72ea347..23a2ce4 100644 --- a/src/graphql/resolvers/transaction-resolver.ts +++ b/src/graphql/resolvers/transaction-resolver.ts @@ -16,9 +16,13 @@ class TransactionArguments { @ArrayMaxSize(20) transactionIds?: string[]; + /** @deprecated */ @Field(() => String, { nullable: true }) headerId?: string; + @Field(() => [String], { nullable: true }) + headerIds?: string[]; + @Field(() => Int, { nullable: true }) inclusionHeight?: number;