From e06c55c1313bf34d85d69a75736809e7f68d7637 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Tue, 7 Mar 2023 08:09:11 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Make=20submitting=20a=20pa?= =?UTF-8?q?rticipant=20a=20bit=20faster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send multiple emails in parallel rather than sequentially. --- .../src/server/routers/polls/participants.ts | 38 +++++++++++-------- apps/web/tests/vote-and-comment.spec.ts | 4 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/apps/web/src/server/routers/polls/participants.ts b/apps/web/src/server/routers/polls/participants.ts index 2663fbaee..741d5a97c 100644 --- a/apps/web/src/server/routers/polls/participants.ts +++ b/apps/web/src/server/routers/polls/participants.ts @@ -88,7 +88,7 @@ export const participants = router({ }); const { poll, ...participant } = res; - + const emailsToSend: Promise[] = []; if (email) { const token = await createToken( { userId: user.id }, @@ -97,23 +97,29 @@ export const participants = router({ }, ); - await sendEmail("NewParticipantConfirmationEmail", { - to: email, - subject: `Your response for ${poll.title} has been received`, - props: { - name, - title: poll.title, - editSubmissionUrl: absoluteUrl( - `/p/${poll.participantUrlId}?token=${token}`, - ), - }, - }); + emailsToSend.push( + sendEmail("NewParticipantConfirmationEmail", { + to: email, + subject: `Response submitted: ${poll.title}`, + props: { + name, + title: poll.title, + editSubmissionUrl: absoluteUrl( + `/p/${poll.participantUrlId}?token=${token}`, + ), + }, + }), + ); } - await sendNotification(pollId, { - type: "newParticipant", - participantName: name, - }); + emailsToSend.push( + sendNotification(pollId, { + type: "newParticipant", + participantName: name, + }), + ); + + await Promise.all(emailsToSend); return participant; }), diff --git a/apps/web/tests/vote-and-comment.spec.ts b/apps/web/tests/vote-and-comment.spec.ts index 0a487026e..ecdddbba2 100644 --- a/apps/web/tests/vote-and-comment.spec.ts +++ b/apps/web/tests/vote-and-comment.spec.ts @@ -76,9 +76,7 @@ test.describe.parallel(() => { wait: 5000, }); - expect(email.headers.subject).toBe( - "Your response for Lunch Meeting has been received", - ); + expect(email.headers.subject).toBe("Response submitted: Lunch Meeting"); const $ = load(email.html); const href = $("#editSubmissionUrl").attr("href");