example:
exports.products = (req, res) => {
// var1
const ITEM_LIMIT = 4;
// var2
const page = +req.query.p || 1;
// unimportant part
productModel.getProdCount().then(([count]) => {
const totalItems = count[0]['COUNT(id)'];
productModel.fetchAllProd((page - 1) * ITEM_LIMIT, ITEM_LIMIT).then(([rows]) => {
res.render('general/products', {
prods: rows,
title: 'Products Page',
path: '/products',
currPage: page,
hasNextPage: ITEM_LIMIT * page < totalItems,
havePrevPage: page > 1,
prevPage: page - 1,
nextPage: page + 1,
lastPage: Math.ceil(totalItems / ITEM_LIMIT),
});
});
});
};
As you see I have var1 and var2.
Is it ok to define them as sync like this?
Should I create an async structure for them? What is best practice.
If I use it heavily in this way, for example, if 10 million users run the same function, I think the event loop may get blocked.