Skip to content

Commit

Permalink
add pagination to repoMostHonoredContributors
Browse files Browse the repository at this point in the history
  • Loading branch information
aldolamb committed Aug 23, 2022
1 parent 1c6c497 commit fb0b3ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,9 @@ type Query {
profileData(address: String!): NullableProfile
mostHonoredContributors(count: Float = 10): [ProfileWithClaimsCount!]!
repoMostHonoredContributors(
page: Float = null
perPage: Float = null
repoId: Float!
count: Float = 10
): [ProfileWithClaimsCount!]!
search(text: String!): SearchResults!
}
Expand Down
15 changes: 10 additions & 5 deletions src/graphql/resolvers/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,18 @@ export class CustomProfileResolver {
return finalResults;
}

@Query(returns => [ProfileWithClaimsCount])
@Query(returns => [ProfileWithClaimsCount], { nullable: true })
async repoMostHonoredContributors(
@Ctx() { prisma }: Context,
@Arg('count', { defaultValue: 10 }) count: Number,
@Arg('repoId') repoId: number,
@Arg('perPage', { defaultValue: 6 }) perPage?: number,
@Arg('page', { defaultValue: 1 }) page?: number,
): Promise<ProfileWithClaimsCount[]> {
const logger = createScopedLogger('GQL repoMostHonoredContributors');

logger.info(`Request for repo ${repoId}'s ${count} most honored contributors `);
logger.info(
`Request for repo ${repoId}'s most honored contributors, with ${perPage} results per page and page ${page}`,
);

const endTimer = gqlRequestDurationSeconds.startTimer('repoMostHonoredContributors');

Expand All @@ -243,7 +246,7 @@ export class CustomProfileResolver {
AND c.status = ${ClaimStatus.CLAIMED}::"ClaimStatus" AND r.id = ${repoId}
GROUP BY pf.id
ORDER BY "claimsCount" DESC
LIMIT ${count}
LIMIT ${<number>perPage} OFFSET ${(<number>page - 1) * <number>perPage}
`;

let finalResults = [];
Expand All @@ -254,7 +257,9 @@ export class CustomProfileResolver {
finalResults.push({ profile, claimsCount });
}

logger.debug(`Completed request for repo ${repoId}'s ${count} most honored contributors`);
logger.debug(
`Completed request for repo ${repoId}'s most honored contributors, with ${perPage} results per page and page ${page}`,
);

endTimer({ success: 1 });

Expand Down

0 comments on commit fb0b3ff

Please sign in to comment.