From 26f665e44ddc2bc87dcfda7242e40526ebd77891 Mon Sep 17 00:00:00 2001 From: SepehrGanji Date: Thu, 1 Feb 2024 12:49:25 -0700 Subject: [PATCH] batch headerID --- src/context/header-repository.ts | 20 ++++++++++++++++++++ src/graphql/resolvers/header-resolver.ts | 7 ++++++- src/graphql/schema.graphql | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/context/header-repository.ts b/src/context/header-repository.ts index 69428fe..74cf520 100644 --- a/src/context/header-repository.ts +++ b/src/context/header-repository.ts @@ -1,5 +1,10 @@ import { HeaderEntity } from "../entities"; import { BaseRepository, RepositoryDataContext } from "./base-repository"; +import {FindManyParams} from "./repository-interface"; + +type HeaderFindOptions = FindManyParams & { + headerIds?: string[]; +} export class HeaderRepository extends BaseRepository { constructor(context: RepositoryDataContext) { @@ -12,6 +17,21 @@ export class HeaderRepository extends BaseRepository { }); } + public override async find(options: HeaderFindOptions): Promise { + const headerIds = options.headerIds ?? []; + if(options.where?.headerId) { + headerIds.push(options.where.headerId); + delete options.where.headerId; + } + return this.findBase(options, (filterQuery) => { + if(headerIds.length > 0) { + filterQuery = filterQuery.andWhere("header.headerId IN (:...headerIds)", { headerIds }); + } + + return filterQuery; + }) + } + public async getMaxHeight(): Promise { const { height } = await this.repository .createQueryBuilder("header") diff --git a/src/graphql/resolvers/header-resolver.ts b/src/graphql/resolvers/header-resolver.ts index 4a3393b..a5dd606 100644 --- a/src/graphql/resolvers/header-resolver.ts +++ b/src/graphql/resolvers/header-resolver.ts @@ -7,9 +7,13 @@ import { PaginationArguments } from "./pagination-arguments"; @ArgsType() class BlockHeadersQueryArgs extends PaginationArguments { + /** @deprecated */ @Field(() => String, { nullable: true }) headerId?: string; + @Field(() => [String], { nullable: true }) + headerIds?: string[]; + @Field(() => String, { nullable: true }) parentId?: string; @@ -24,7 +28,7 @@ class BlockHeadersQueryArgs extends PaginationArguments { export class HeaderResolver { @Query(() => [Header]) async blockHeaders( - @Args({ validate: true }) { headerId, parentId, height, skip, take }: BlockHeadersQueryArgs, + @Args({ validate: true }) { headerId, headerIds, parentId, height, skip, take }: BlockHeadersQueryArgs, @Ctx() context: GraphQLContext, @Info() info: GraphQLResolveInfo ) { @@ -35,6 +39,7 @@ export class HeaderResolver { parentId, height }), + headerIds, skip, take }); diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index dc403cc..3b7a9ba 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -223,7 +223,7 @@ type Mutation { type Query { addresses(addresses: [String!]!): [Address!]! - blockHeaders(headerId: String, height: Int, parentId: String, skip: Int = 0, take: Int = 10): [Header!]! + blockHeaders(headerId: String, headerIds: [String!], height: Int, parentId: String, skip: Int = 0, take: Int = 10): [Header!]! blocks(headerId: String, height: Int, maxHeight: Int, minHeight: Int, skip: Int = 0, take: Int = 10): [Block!]! boxes(address: String, addresses: [String!], boxId: String, boxIds: [String!], ergoTree: String, ergoTreeTemplateHash: String, ergoTrees: [String!], headerId: String, heightType: HeightFilterType = settlement, maxHeight: Int, minHeight: Int, registers: Registers, skip: Int = 0, spent: Boolean, take: Int = 50, tokenId: String, transactionId: String): [Box!]! dataInputs(boxId: String, headerId: String, skip: Int = 0, take: Int = 50, transactionId: String): [DataInput!]!