Skip to content

A local-first personal finance app

parallelise contributor points calculations (#5465)

Matt Fiddaman994b95905077
diff --git a/.github/scripts/count-points.mjs b/.github/scripts/count-points.mjs
index 6e8954f320..0662fb0346 100644
--- a/.github/scripts/count-points.mjs
+++ b/.github/scripts/count-points.mjs
@@ -1,5 +1,8 @@
import { Octokit } from '@octokit/rest';
import { minimatch } from 'minimatch';
+import pLimit from 'p-limit';
+
+const limit = pLimit(30);
/** Repository-specific configuration for points calculation */
const REPOSITORY_CONFIG = new Map([
@@ -136,75 +139,69 @@ async function countContributorPoints(repo) {
);
// Get reviews and PR details for each PR
- for (const pr of recentPRs) {
- const { data: reviews } = await octokit.pulls.listReviews({
- owner,
- repo,
- pull_number: pr.number,
- });
-
- // Get list of modified files with pagination
- const modifiedFiles = await octokit.paginate(
- octokit.pulls.listFiles,
- {
- owner,
- repo,
- pull_number: pr.number,
- per_page: 100, // Maximum allowed by GitHub API
- },
- response => response.data,
- );
-
- // Calculate points based on PR size, excluding specified files
- const totalChanges = modifiedFiles
- .filter(
- file =>
- !config.EXCLUDED_FILES.some(pattern =>
- minimatch(file.filename, pattern),
+ await Promise.all(
+ recentPRs.map(pr =>
+ limit(async () => {
+ const [reviews, modifiedFiles] = await Promise.all([
+ octokit.pulls.listReviews({ owner, repo, pull_number: pr.number }),
+ octokit.paginate(
+ octokit.pulls.listFiles,
+ {
+ owner,
+ repo,
+ pull_number: pr.number,
+ per_page: 100,
+ },
+ res => res.data,
),
- )
- .reduce((sum, file) => sum + file.additions + file.deletions, 0);
-
- // Check if this is a release PR
- const isReleasePR = pr.title.match(/πŸ”–.*\d+\.\d+\.\d+/);
-
- // Calculate points for reviewers based on PR size
- const prPoints =
- config.PR_REVIEW_POINT_TIERS.find(tier => totalChanges >= tier.minChanges)
- ?.points ?? 0;
-
- if (isReleasePR) {
- // Award points to the PR creator if it's a release PR
- if (stats.has(pr.user.login)) {
- const creatorStats = stats.get(pr.user.login);
- creatorStats.reviews.push({
- pr: pr.number.toString(),
- points: config.POINTS_PER_RELEASE_PR,
- isReleaseCreator: true,
- });
- creatorStats.points += config.POINTS_PER_RELEASE_PR;
- }
- } else {
- // Add points to the reviewers
- const uniqueReviewers = new Set();
- reviews
- .filter(
- review =>
- stats.has(review.user?.login) &&
- review.state === 'APPROVED' &&
- !uniqueReviewers.has(review.user?.login),
- )
- .forEach(({ user: { login: reviewer } }) => {
- uniqueReviewers.add(reviewer);
- const userStats = stats.get(reviewer);
- userStats.reviews.push({
- pr: pr.number.toString(),
- points: prPoints,
- });
- userStats.points += prPoints;
- });
- }
- }
+ ]);
+
+ const totalChanges = modifiedFiles
+ .filter(
+ file =>
+ !config.EXCLUDED_FILES.some(pattern =>
+ minimatch(file.filename, pattern),
+ ),
+ )
+ .reduce((sum, file) => sum + file.additions + file.deletions, 0);
+
+ const isReleasePR = pr.title.match(/πŸ”–.*\d+\.\d+\.\d+/);
+ const prPoints =
+ config.PR_REVIEW_POINT_TIERS.find(t => totalChanges >= t.minChanges)
+ ?.points ?? 0;
+
+ if (isReleasePR) {
+ if (stats.has(pr.user.login)) {
+ const creatorStats = stats.get(pr.user.login);
+ creatorStats.reviews.push({
+ pr: pr.number.toString(),
+ points: config.POINTS_PER_RELEASE_PR,
+ isReleaseCreator: true,
+ });
+ creatorStats.points += config.POINTS_PER_RELEASE_PR;
+ }
+ } else {
+ const uniqueReviewers = new Set();
+ reviews.data
+ .filter(
+ review =>
+ stats.has(review.user?.login) &&
+ review.state === 'APPROVED' &&
+ !uniqueReviewers.has(review.user?.login),
+ )
+ .forEach(({ user: { login: reviewer } }) => {
+ uniqueReviewers.add(reviewer);
+ const userStats = stats.get(reviewer);
+ userStats.reviews.push({
+ pr: pr.number.toString(),
+ points: prPoints,
+ });
+ userStats.points += prPoints;
+ });
+ }
+ }),
+ ),
+ );
// Get all issues with label events in the last month
const issues = await octokit.paginate(octokit.issues.listForRepo, {
@@ -218,49 +215,48 @@ async function countContributorPoints(repo) {
});
// Get label events for each issue
- for (const issue of issues) {
- const { data: events } = await octokit.issues.listEventsForTimeline({
- owner,
- repo,
- issue_number: issue.number,
- });
-
- // Process events
- events
- .filter(event => {
- // Always compare UTC times
- const createdAt = new Date(event.created_at);
- return (
- createdAt.getTime() > since.getTime() &&
- createdAt.getTime() <= until.getTime() &&
- stats.has(event.actor?.login)
- );
- })
- .forEach(event => {
- if (
- event.event === 'unlabeled' &&
- event.label &&
- event.label.name.toLowerCase() === 'needs triage'
- ) {
- const remover = event.actor.login;
- const userStats = stats.get(remover);
- if (userStats) {
- userStats.labelRemovals.push(issue.number.toString());
- userStats.points += config.POINTS_PER_ISSUE_TRIAGE_ACTION;
- }
- }
+ await Promise.all(
+ issues.map(issue =>
+ limit(async () => {
+ const { data: events } = await octokit.issues.listEventsForTimeline({
+ owner,
+ repo,
+ issue_number: issue.number,
+ });
- // Check if the issue was closed with "no planned" status
- if (event.event === 'closed' && event.state_reason === 'not_planned') {
- const closer = event.actor.login;
- const userStats = stats.get(closer);
- if (userStats) {
- userStats.issueClosings.push(issue.number.toString());
- userStats.points += config.POINTS_PER_ISSUE_CLOSING_ACTION;
- }
- }
- });
- }
+ events
+ .filter(event => {
+ const createdAt = new Date(event.created_at);
+ return (
+ createdAt.getTime() > since.getTime() &&
+ createdAt.getTime() <= until.getTime() &&
+ stats.has(event.actor?.login)
+ );
+ })
+ .forEach(event => {
+ if (
+ event.event === 'unlabeled' &&
+ event.label?.name.toLowerCase() === 'needs triage'
+ ) {
+ const remover = event.actor.login;
+ const userStats = stats.get(remover);
+ userStats.labelRemovals.push(issue.number.toString());
+ userStats.points += config.POINTS_PER_ISSUE_TRIAGE_ACTION;
+ }
+
+ if (
+ event.event === 'closed' &&
+ event.state_reason === 'not_planned'
+ ) {
+ const closer = event.actor.login;
+ const userStats = stats.get(closer);
+ userStats.issueClosings.push(issue.number.toString());
+ userStats.points += config.POINTS_PER_ISSUE_CLOSING_ACTION;
+ }
+ });
+ }),
+ ),
+ );
// Print all statistics
printStats(
diff --git a/package.json b/package.json
index b628494686..67c4015ed3 100644
--- a/package.json
+++ b/package.json
@@ -73,6 +73,7 @@
"minimatch": "^10.0.3",
"node-jq": "^6.0.1",
"npm-run-all": "^4.1.5",
+ "p-limit": "^6.2.0",
"prettier": "^3.5.3",
"prompts": "^2.4.2",
"source-map-support": "^0.5.21",
diff --git a/yarn.lock b/yarn.lock
index 27f2dd2d92..2945027043 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7630,6 +7630,7 @@ __metadata:
minimatch: "npm:^10.0.3"
node-jq: "npm:^6.0.1"
npm-run-all: "npm:^4.1.5"
+ p-limit: "npm:^6.2.0"
prettier: "npm:^3.5.3"
prompts: "npm:^2.4.2"
source-map-support: "npm:^0.5.21"
@@ -15957,6 +15958,15 @@ __metadata:
languageName: node
linkType: hard
+"p-limit@npm:^6.2.0":
+ version: 6.2.0
+ resolution: "p-limit@npm:6.2.0"
+ dependencies:
+ yocto-queue: "npm:^1.1.1"
+ checksum: 10/70e8df3e5f1c173c9bd9fa8390a3c5c2797505240ae42973536992b1f5f59a922153c2f35ff1bf36fb72a0f025b0f13fca062a4233e830adad446960d56b4d84
+ languageName: node
+ linkType: hard
+
"p-locate@npm:^4.1.0":
version: 4.1.0
resolution: "p-locate@npm:4.1.0"
@@ -21466,6 +21476,13 @@ __metadata:
languageName: node
linkType: hard
+"yocto-queue@npm:^1.1.1":
+ version: 1.2.1
+ resolution: "yocto-queue@npm:1.2.1"
+ checksum: 10/0843d6c2c0558e5c06e98edf9c17942f25c769e21b519303a5c2adefd5b738c9b2054204dc856ac0cd9d134b1bc27d928ce84fd23c9e2423b7e013d5a6f50577
+ languageName: node
+ linkType: hard
+
"zod@npm:^3.23.8":
version: 3.24.4
resolution: "zod@npm:3.24.4"