Skip to content

Commit

Permalink
Custom recipe fetch by-page call is now parallelized with count
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy committed Mar 23, 2019
1 parent cc1a37d commit 56ec49f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Backend/routes/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 56ec49f

Please sign in to comment.