From 5876c47a2db5b2049ef1ee79712fa148c7c892d9 Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Tue, 3 Nov 2026 04:00:05 +0530 Subject: [PATCH] perf: deduplicate changelog authors per day with a set --- resources/js/lib/changelog.ts | 7 ++++--- tests/Unit/Changelog.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/js/lib/changelog.ts b/resources/js/lib/changelog.ts index 4aa6d9636..a4df9a826 100644 --- a/resources/js/lib/changelog.ts +++ b/resources/js/lib/changelog.ts @@ -43,6 +43,7 @@ export function changelogDays( timeZone: string, ): ChangelogDay[] { const days: ChangelogDay[] = []; + let seenAuthors = new Set(); for (const commit of commits) { const date = new Date(commit.committed_at).toLocaleDateString('en-CA', { @@ -53,13 +54,13 @@ export function changelogDays( if (day?.date !== date) { day = { date, commits: [], authors: [] }; days.push(day); + seenAuthors = new Set(); } day.commits.push(commit); - if ( - !day.authors.some((author) => author.login === commit.author.login) - ) { + if (!seenAuthors.has(commit.author.login)) { + seenAuthors.add(commit.author.login); day.authors.push(commit.author); } } diff --git a/tests/Unit/Changelog.test.ts b/tests/Unit/Changelog.test.ts index 23d33f856..b8b7d7542 100644 --- a/tests/Unit/Changelog.test.ts +++ b/tests/Unit/Changelog.test.ts @@ -94,3 +94,14 @@ void test('names the day relative to today in the reader’s time zone', () => { assert.deepEqual(changelogDayHeading('2026-10-14', 'Europe/Budapest', now), { title: 'Wednesday', date: 'Oct 14' }); assert.deepEqual(changelogDayHeading('2025-12-31', 'Europe/Budapest', now), { title: 'Wednesday', date: 'Dec 31, 2025' }); }); + +void test('keeps the first author occurrence even for many commits on the same day', () => { + const commits = Array.from({ length: 200 }, (_, index) => + commit(index, '2026-10-18T12:00:00Z', index % 2 === 0 ? 'alice' : 'bob'), + ); + const days = changelogDays(commits, 'UTC'); + + assert.equal(days.length, 1); + assert.equal(days[0].commits.length, 200); + assert.deepEqual(days[0].authors.map(({ login }) => login), ['alice', 'bob']); +});