From 74e0f4dfb3db4dff9274605a64fe719ae11d3fd0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 5 Jun 2021 18:40:55 -0700 Subject: [PATCH] fix: Parallelize loading attachments in document presenter (#2184) closes #2157 --- server/presenters/document.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/presenters/document.js b/server/presenters/document.js index edfc4fa8..c98893d7 100644 --- a/server/presenters/document.js +++ b/server/presenters/document.js @@ -12,13 +12,15 @@ type Options = { async function replaceImageAttachments(text: string) { const attachmentIds = parseAttachmentIds(text); - for (const id of attachmentIds) { - const attachment = await Attachment.findByPk(id); - if (attachment) { - const accessUrl = await getSignedImageUrl(attachment.key); - text = text.replace(attachment.redirectUrl, accessUrl); - } - } + await Promise.all( + attachmentIds.map(async (id) => { + const attachment = await Attachment.findByPk(id); + if (attachment) { + const accessUrl = await getSignedImageUrl(attachment.key); + text = text.replace(attachment.redirectUrl, accessUrl); + } + }) + ); return text; }