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

chore: optimized stats calculation by fetching contribution data in parallel using Promise.all #416

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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
25 changes: 17 additions & 8 deletions src/fetcher/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,26 @@ async function stats(username: string): Promise<User> {
const startYear = await getUserJoinYear(username);
const endYear = new Date().getFullYear();

let TotalCommitContributions = 0;
let RestrictedContributionsCount = 0;
let TotalPullRequestReviewContributions = 0;

const contributionPromises = [];
for (let year = startYear; year <= endYear; year++) {
const contributions = await fetchContributions(username, year);
TotalCommitContributions += contributions.totalCommitContributions;
RestrictedContributionsCount += contributions.restrictedContributionsCount;
TotalPullRequestReviewContributions += contributions.totalPullRequestReviewContributions;
contributionPromises.push(fetchContributions(username, year));
}

const contributions = await Promise.all(contributionPromises);

const TotalCommitContributions = contributions.reduce(
(total, contribution) => total + contribution.totalCommitContributions,
0
);
const RestrictedContributionsCount = contributions.reduce(
(total, contribution) => total + contribution.restrictedContributionsCount,
0
);
const TotalPullRequestReviewContributions = contributions.reduce(
(total, contribution) => total + contribution.totalPullRequestReviewContributions,
0
);

const data = await axios({
method: "post",
url: "https://api.github.com/graphql",
Expand Down
Loading