From 1551f6d474ff3f6468774d9b2895a7fe6fe8daef Mon Sep 17 00:00:00 2001 From: Isaias Tavares Date: Thu, 5 Nov 2026 01:15:15 -0300 Subject: [PATCH] refactor(db): group duplicate emails by pushing into each group The duplicate-email report rebuilt each group's array with a spread on every row. Pushing into the group that the map already holds says the same thing without the copies. --- server/src/db/email-case-index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/db/email-case-index.ts b/server/src/db/email-case-index.ts index f1b08e0c8..7df239fd0 100644 --- a/server/src/db/email-case-index.ts +++ b/server/src/db/email-case-index.ts @@ -24,7 +24,11 @@ export async function ensureEmailCaseIndex(connection: Connection): Promise 1) ORDER BY id`, ); const duplicates = new Map(); - for (const row of rows) duplicates.set(row.email_key, [...(duplicates.get(row.email_key) ?? []), row.id]); + for (const row of rows) { + const group = duplicates.get(row.email_key); + if (group) group.push(row.id); + else duplicates.set(row.email_key, [row.id]); + } if (duplicates.size > 0) { const ids = [...duplicates.values()].map((group) => group.join(', ')); console.warn(