Skip to content

Commit

Permalink
Merge pull request #87 from nautls/batches-in-blockHeaders
Browse files Browse the repository at this point in the history
batch headerID
  • Loading branch information
arobsn authored Sep 20, 2024
2 parents 0738cac + 26f665e commit 71b7ea4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/context/header-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { HeaderEntity } from "../entities";
import { BaseRepository, RepositoryDataContext } from "./base-repository";
import {FindManyParams} from "./repository-interface";

type HeaderFindOptions = FindManyParams<HeaderEntity> & {
headerIds?: string[];
}

export class HeaderRepository extends BaseRepository<HeaderEntity> {
constructor(context: RepositoryDataContext) {
Expand All @@ -12,6 +17,21 @@ export class HeaderRepository extends BaseRepository<HeaderEntity> {
});
}

public override async find(options: HeaderFindOptions): Promise<HeaderEntity[]> {
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<number | undefined> {
const { height } = await this.repository
.createQueryBuilder("header")
Expand Down
7 changes: 6 additions & 1 deletion src/graphql/resolvers/header-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
) {
Expand All @@ -35,6 +39,7 @@ export class HeaderResolver {
parentId,
height
}),
headerIds,
skip,
take
});
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!
Expand Down

0 comments on commit 71b7ea4

Please sign in to comment.