Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch headerID #87

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading