Remove unnecessary allocations from rest handler
Correctly cache the list of `preHandlers` so that they are built only once in application lifetime. Remove array concatenation, use a new callback function instead.
This commit is contained in:
parent
32ed60904c
commit
0058efb2ee
|
@ -23,6 +23,8 @@ module.exports = rest;
|
|||
*/
|
||||
|
||||
function rest() {
|
||||
var preHandlers;
|
||||
|
||||
return function restApiHandler(req, res, next) {
|
||||
var app = req.app;
|
||||
var restHandler = app.handler('rest');
|
||||
|
@ -33,8 +35,6 @@ function rest() {
|
|||
return res.send(app.remotes().toJSON());
|
||||
}
|
||||
|
||||
var preHandlers;
|
||||
|
||||
if (!preHandlers) {
|
||||
preHandlers = [];
|
||||
var remotingOptions = app.get('remoting') || {};
|
||||
|
@ -58,8 +58,14 @@ function rest() {
|
|||
}
|
||||
}
|
||||
|
||||
async.eachSeries(preHandlers.concat(restHandler), function(handler, done) {
|
||||
async.eachSeries(
|
||||
preHandlers,
|
||||
function(handler, done) {
|
||||
handler(req, res, done);
|
||||
}, next);
|
||||
},
|
||||
function(err) {
|
||||
if (err) return next(err);
|
||||
restHandler(req, res, next);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue