From f202fe8bfed1194bdfecff15f2386c19c359097f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 04:25:12 +0000 Subject: [PATCH] perf(github): optimize calculateMostActiveDay by removing Date parsing in loop Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index d35c21bf..46d39698 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -89,14 +89,20 @@ function calculateStreaks(calendar: { count: number }[]): { longestStreak: numbe } function calculateMostActiveDay(calendar: { date: string; count: number }[]): string | null { + if (calendar.length === 0) { + return null; + } + const weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; const weekdayTotals = Array.from({ length: 7 }, () => 0); + const startDay = new Date(`${calendar[0].date}T00:00:00Z`).getUTCDay(); - for (const day of calendar) { + for (let i = 0; i < calendar.length; i++) { + const day = calendar[i]; if (day.count === 0) { continue; } - const weekday = new Date(`${day.date}T00:00:00Z`).getUTCDay(); + const weekday = (startDay + i) % 7; weekdayTotals[weekday] += day.count; }