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

Add Pagination To repoMostHonoredContributors #279

Merged
merged 1 commit into from
Aug 23, 2022
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
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