From eaaf83561c8bf949cb4dcda8252ffcd4abed9d91 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 17 Jun 2024 13:03:02 +0200 Subject: [PATCH] fix: refs #5995 Optimized downloadCmrsZip --- modules/route/back/methods/route/downloadCmrsZip.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/route/back/methods/route/downloadCmrsZip.js b/modules/route/back/methods/route/downloadCmrsZip.js index c6934edca..895ff7a16 100644 --- a/modules/route/back/methods/route/downloadCmrsZip.js +++ b/modules/route/back/methods/route/downloadCmrsZip.js @@ -41,14 +41,16 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - ids = ids.split(','); - - for (const id of ids) { + const downloadAddZip = async id => { ctx.args = ctx.args || {}; ctx.args.id = Number(id); const [data] = await models.Route.cmr(ctx, myOptions); zip.file(`${id}.pdf`, data, {binary: true}); - } + }; + + ids = ids.split(','); + const promises = ids.map(id => downloadAddZip(id)); + await Promise.all(promises); const zipStream = zip.generateNodeStream({streamFiles: true}); return [zipStream, 'application/zip', `filename="cmrs.zip"`]; };