fix: Parallelize loading attachments in document presenter (#2184)

closes #2157
This commit is contained in:
Tom Moor
2021-06-05 18:40:55 -07:00
committed by GitHub
parent 5c7f2cf164
commit 74e0f4dfb3

View File

@ -12,13 +12,15 @@ type Options = {
async function replaceImageAttachments(text: string) { async function replaceImageAttachments(text: string) {
const attachmentIds = parseAttachmentIds(text); const attachmentIds = parseAttachmentIds(text);
for (const id of attachmentIds) { await Promise.all(
const attachment = await Attachment.findByPk(id); attachmentIds.map(async (id) => {
if (attachment) { const attachment = await Attachment.findByPk(id);
const accessUrl = await getSignedImageUrl(attachment.key); if (attachment) {
text = text.replace(attachment.redirectUrl, accessUrl); const accessUrl = await getSignedImageUrl(attachment.key);
} text = text.replace(attachment.redirectUrl, accessUrl);
} }
})
);
return text; return text;
} }