From 9273c6911562f5e08cda608a8095baff0280b8b3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 07:11:32 +0000 Subject: [PATCH] refactor: optimize totalRepoCount calculation in fetchRepositoriesREST Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index ed7dd37f..f8bca661 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -379,8 +379,12 @@ async function fetchRepositoriesREST(username: string): Promise } } - const totalRepoCount = Array.from(languageRepoCount.values()).reduce((a, b) => a + b, 0); - const languages: LanguageStats[] = getTopK(languageRepoCount, 10).map(({ name, count }) => ({ + let totalRepoCount = 0; + const topLanguages = getTopK(languageRepoCount, 10); + for (const count of languageRepoCount.values()) { + totalRepoCount += count; + } + const languages: LanguageStats[] = topLanguages.map(({ name, count }) => ({ name, bytes: count, percentage: totalRepoCount > 0 ? Math.round((count / totalRepoCount) * 1000) / 10 : 0,