Skip to content

Commit

Permalink
batch headerId in transaction query
Browse files Browse the repository at this point in the history
  • Loading branch information
SepehrGanji committed Jan 30, 2024
1 parent 5545ee5 commit ab78b1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/context/transactions-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type TransactionFindOptions = FindManyParams<TransactionEntity> & {
address?: string;
addresses?: string[];
transactionIds?: string[];
headerIds?: string[];
};

export class TransactionRepository extends BaseRepository<TransactionEntity> {
Expand All @@ -23,7 +24,7 @@ export class TransactionRepository extends BaseRepository<TransactionEntity> {
}

public override async find(options: TransactionFindOptions): Promise<TransactionEntity[]> {
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)
: [];
Expand Down Expand Up @@ -65,13 +66,23 @@ export class TransactionRepository extends BaseRepository<TransactionEntity> {
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
})
);

Expand Down
4 changes: 4 additions & 0 deletions src/graphql/resolvers/transaction-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ab78b1e

Please sign in to comment.