Skip to content

Commit

Permalink
Fix perfs
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Feb 14, 2024
1 parent 7368c8a commit 8d21f94
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const Contributors = async () => {
const contributors = await findAll(userModel);
const pullRequests = await findAll(pullRequestModel);

const pullRequestByAuthor = pullRequests.reduce((acc, pr) => {
acc[pr.authorId] = acc[pr.authorId] ? acc[pr.authorId] + 1 : 1;
return acc;
}, {});

const fitlerContributors = contributors
.filter((contributor) => contributor.isEmployee === '0')
.filter(
Expand All @@ -28,9 +33,7 @@ const Contributors = async () => {
].includes(contributor.id),
)
.map((contributor) => {
contributor.pullRequestCount = pullRequests.filter(
(pr) => pr.authorId === contributor.id,
).length;
contributor.pullRequestCount = pullRequestByAuthor[contributor.id] || 0;

return contributor;
})
Expand Down

0 comments on commit 8d21f94

Please sign in to comment.