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.
This commit is contained in:
Isaias Tavares
2026-11-05 01:15:15 -03:00
parent 783ad5c0f1
commit 1551f6d474
+5 -1
View File
@@ -24,7 +24,11 @@ export async function ensureEmailCaseIndex(connection: Connection): Promise<void
`(SELECT lower(email) FROM users GROUP BY lower(email) HAVING COUNT(*) > 1) ORDER BY id`,
);
const duplicates = new Map<string, number[]>();
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(