micheal-kyagulanyi / allether-pizza-api

Simple pizza order API
0 stars 1 forks source link

optimizing async performance #4

Open 0xF48 opened 4 years ago

0xF48 commented 4 years ago

in order to avoid long loading screens ( I have these issues in my backend code as well which need to be refactored ), parts of the code need to run async.

what does you mean? don't I already have async code using promises? every time you use .then you create a synchronous chain. that means that you have to first find all the crusts, then you have to find all the toppings, then you have to find all the meats, etc..

okay, how can I run all of those database queries all at once?

Using Promise.all to first find all matching toppings in the database with proper mongodb query objects in an array and then once they all return their promise, going through all the returned objects and adding them to the order which gets returned in the response object.

using bluebird - npm using native promise - mdn

0xF48 commented 4 years ago

use mongodb query objects to find all the toppings all at once - https://github.com/micheal-kyagulanyi/allether-pizza-api/issues/2