0

How to improve this code, because whenever I run siege command

siege -d0 -c 100 http://localhost/destinations/list, the cpu usage shoot up to 100%?

Is there any thing that I might be doing wrong?

/**
 * GET /destinations
 */
exports.list = function (req, res, next) {

    var query = {
        status : 'active'
    };

    Destination.find(query).populate('landmark', 'name area urlName').populate('city', 'name urlName').populate('image').exec(function(err, destinations) {
        if (err)
        {
            console.log(err + '\n' + __filename + ' ' + __functionName + ' ' + __lineNumber);
            res.json({status : 'failed', data : {}, reason : 'Destination not found'});
            return;
        }

        Destination.populate(destinations, {path : 'landmark.area', model : 'Area', select : 'city'}, function(err, destinations) {
            Destination.populate(destinations, {path : 'landmark.area.city', model : 'City', select : 'urlName'}, function(err, destinations) {
                res.json({status : 'success', data : destinations});
            });
        });

    });

};
hrusli
  • 283
  • 3
  • 14

0 Answers0