From 56ec49fa6f23d60fc9b170be9e89f5f10b4fd689 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Sat, 23 Mar 2019 14:04:07 -0700 Subject: [PATCH] Custom recipe fetch by-page call is now parallelized with count --- Backend/routes/recipes.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Backend/routes/recipes.js b/Backend/routes/recipes.js index 755c9848a..f51ce058c 100644 --- a/Backend/routes/recipes.js +++ b/Backend/routes/recipes.js @@ -251,15 +251,16 @@ router.get( Recipe._validateIncludedElements(fetchQueryOptions); - SQ.query(countQuery, countQueryOptions).then(countResult => { + Promise.all([ + SQ.query(countQuery, countQueryOptions), + SQ.query(fetchQuery, fetchQueryOptions) + ]).then(([countResult, recipes]) => { let totalCount = parseInt(countResult[0].count, 10); - return SQ.query(fetchQuery, fetchQueryOptions).then(recipes => { - res.status(200).json({ - data: recipes, - totalCount - }); - }) + res.status(200).json({ + data: recipes, + totalCount + }); }).catch(next); });