Remove all conditional branches to call req.profiler
req.profiler is created in a middleware for all requests.
This commit is contained in:
parent
1ca56fb81c
commit
cad02bfad7
@ -95,9 +95,7 @@ AuthApi.prototype.authorize = function(req, callback) {
|
|||||||
self.authorizedByAPIKey(user, req, this);
|
self.authorizedByAPIKey(user, req, this);
|
||||||
},
|
},
|
||||||
function checkApiKey(err, authorized){
|
function checkApiKey(err, authorized){
|
||||||
if (req.profiler) {
|
req.profiler.done('authorizedByAPIKey');
|
||||||
req.profiler.done('authorizedByAPIKey');
|
|
||||||
}
|
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
// if not authorized by api_key, continue
|
// if not authorized by api_key, continue
|
||||||
@ -131,9 +129,7 @@ AuthApi.prototype.authorize = function(req, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.pgConnection.setDBAuth(user, req.params, function(err) {
|
self.pgConnection.setDBAuth(user, req.params, function(err) {
|
||||||
if (req.profiler) {
|
req.profiler.done('setDBAuth');
|
||||||
req.profiler.done('setDBAuth');
|
|
||||||
}
|
|
||||||
callback(err, true); // authorized (or error)
|
callback(err, true); // authorized (or error)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,7 @@ BaseController.prototype.req2params = function(req, callback){
|
|||||||
lzmaWorker.decompress(
|
lzmaWorker.decompress(
|
||||||
lzma,
|
lzma,
|
||||||
function(result) {
|
function(result) {
|
||||||
if (req.profiler) {
|
req.profiler.done('lzma');
|
||||||
req.profiler.done('lzma');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
delete req.query.lzma;
|
delete req.query.lzma;
|
||||||
_.extend(req.query, JSON.parse(result));
|
_.extend(req.query, JSON.parse(result));
|
||||||
@ -115,18 +113,14 @@ BaseController.prototype.req2params = function(req, callback){
|
|||||||
// bring all query values onto req.params object
|
// bring all query values onto req.params object
|
||||||
_.extend(req.params, req.query);
|
_.extend(req.params, req.query);
|
||||||
|
|
||||||
if (req.profiler) {
|
req.profiler.done('req2params.setup');
|
||||||
req.profiler.done('req2params.setup');
|
|
||||||
}
|
|
||||||
|
|
||||||
step(
|
step(
|
||||||
function getPrivacy(){
|
function getPrivacy(){
|
||||||
self.authApi.authorize(req, this);
|
self.authApi.authorize(req, this);
|
||||||
},
|
},
|
||||||
function validateAuthorization(err, authorized) {
|
function validateAuthorization(err, authorized) {
|
||||||
if (req.profiler) {
|
req.profiler.done('authorize');
|
||||||
req.profiler.done('authorize');
|
|
||||||
}
|
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
if(!authorized) {
|
if(!authorized) {
|
||||||
err = new Error("Sorry, you are unauthorized (permission denied)");
|
err = new Error("Sorry, you are unauthorized (permission denied)");
|
||||||
@ -167,9 +161,7 @@ BaseController.prototype.send = function(req, res, body, status, headers) {
|
|||||||
res.set('X-Served-By-DB-Host', req.params.dbhost);
|
res.set('X-Served-By-DB-Host', req.params.dbhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.profiler) {
|
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
|
||||||
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
res.set(headers);
|
res.set(headers);
|
||||||
@ -187,14 +179,12 @@ BaseController.prototype.send = function(req, res, body, status, headers) {
|
|||||||
res.send(body);
|
res.send(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.profiler) {
|
try {
|
||||||
try {
|
// May throw due to dns, see
|
||||||
// May throw due to dns, see
|
// See http://github.com/CartoDB/Windshaft/issues/166
|
||||||
// See http://github.com/CartoDB/Windshaft/issues/166
|
req.profiler.sendStats();
|
||||||
req.profiler.sendStats();
|
} catch (err) {
|
||||||
} catch (err) {
|
debug("error sending profiling stats: " + err);
|
||||||
debug("error sending profiling stats: " + err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// jshint maxcomplexity:6
|
// jshint maxcomplexity:6
|
||||||
|
@ -87,9 +87,7 @@ MapController.prototype.createPost = function(req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MapController.prototype.instantiate = function(req, res) {
|
MapController.prototype.instantiate = function(req, res) {
|
||||||
if (req.profiler) {
|
req.profiler.start('windshaft-cartodb.instance_template_post');
|
||||||
req.profiler.start('windshaft-cartodb.instance_template_post');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instantiateTemplate(req, res, function prepareTemplateParams(callback) {
|
this.instantiateTemplate(req, res, function prepareTemplateParams(callback) {
|
||||||
if (!req.is('application/json')) {
|
if (!req.is('application/json')) {
|
||||||
@ -100,9 +98,7 @@ MapController.prototype.instantiate = function(req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MapController.prototype.jsonp = function(req, res) {
|
MapController.prototype.jsonp = function(req, res) {
|
||||||
if (req.profiler) {
|
req.profiler.start('windshaft-cartodb.instance_template_get');
|
||||||
req.profiler.start('windshaft-cartodb.instance_template_get');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instantiateTemplate(req, res, function prepareJsonTemplateParams(callback) {
|
this.instantiateTemplate(req, res, function prepareJsonTemplateParams(callback) {
|
||||||
var err = null;
|
var err = null;
|
||||||
@ -303,9 +299,7 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
|
|||||||
// take place before proceeding. Error will be logged
|
// take place before proceeding. Error will be logged
|
||||||
// asynchronously
|
// asynchronously
|
||||||
this.metadataBackend.incMapviewCount(username, mapconfig.obj().stat_tag, function(err) {
|
this.metadataBackend.incMapviewCount(username, mapconfig.obj().stat_tag, function(err) {
|
||||||
if (req.profiler) {
|
req.profiler.done('incMapviewCount');
|
||||||
req.profiler.done('incMapviewCount');
|
|
||||||
}
|
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
global.logger.log("ERROR: failed to increment mapview count for user '" + username + "': " + err);
|
global.logger.log("ERROR: failed to increment mapview count for user '" + username + "': " + err);
|
||||||
}
|
}
|
||||||
@ -328,9 +322,7 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
|
|||||||
QueryTables.getAffectedTablesFromQuery(connection, sql, this);
|
QueryTables.getAffectedTablesFromQuery(connection, sql, this);
|
||||||
},
|
},
|
||||||
function handleAffectedTablesAndLastUpdatedTime(err, result) {
|
function handleAffectedTablesAndLastUpdatedTime(err, result) {
|
||||||
if (req.profiler) {
|
req.profiler.done('queryTablesAndLastUpdated');
|
||||||
req.profiler.done('queryTablesAndLastUpdated');
|
|
||||||
}
|
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
// feed affected tables cache so it can be reused from, for instance, layergroup controller
|
// feed affected tables cache so it can be reused from, for instance, layergroup controller
|
||||||
self.layergroupAffectedTables.set(dbName, layergroupId, result);
|
self.layergroupAffectedTables.set(dbName, layergroupId, result);
|
||||||
|
@ -100,9 +100,7 @@ NamedMapsController.prototype.tile = function(req, res) {
|
|||||||
self.tileBackend.getTile(namedMapProvider, req.params, this);
|
self.tileBackend.getTile(namedMapProvider, req.params, this);
|
||||||
},
|
},
|
||||||
function handleImage(err, tile, headers, stats) {
|
function handleImage(err, tile, headers, stats) {
|
||||||
if (req.profiler) {
|
req.profiler.add(stats);
|
||||||
req.profiler.add(stats);
|
|
||||||
}
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.sendError(req, res, err, 'NAMED_MAP_TILE');
|
self.sendError(req, res, err, 'NAMED_MAP_TILE');
|
||||||
} else {
|
} else {
|
||||||
@ -176,10 +174,8 @@ NamedMapsController.prototype.staticMap = function(req, res) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function handleImage(err, image, headers, stats) {
|
function handleImage(err, image, headers, stats) {
|
||||||
if (req.profiler) {
|
req.profiler.done('render-' + format);
|
||||||
req.profiler.done('render-' + format);
|
req.profiler.add(stats || {});
|
||||||
req.profiler.add(stats || {});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.sendError(req, res, err, 'STATIC_VIZ_MAP');
|
self.sendError(req, res, err, 'STATIC_VIZ_MAP');
|
||||||
|
@ -91,9 +91,7 @@ NamedMapsAdminController.prototype.update = function(req, res) {
|
|||||||
NamedMapsAdminController.prototype.retrieve = function(req, res) {
|
NamedMapsAdminController.prototype.retrieve = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (req.profiler) {
|
req.profiler.start('windshaft-cartodb.get_template');
|
||||||
req.profiler.start('windshaft-cartodb.get_template');
|
|
||||||
}
|
|
||||||
|
|
||||||
var cdbuser = req.context.user;
|
var cdbuser = req.context.user;
|
||||||
var tpl_id;
|
var tpl_id;
|
||||||
@ -127,9 +125,7 @@ NamedMapsAdminController.prototype.retrieve = function(req, res) {
|
|||||||
NamedMapsAdminController.prototype.destroy = function(req, res) {
|
NamedMapsAdminController.prototype.destroy = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (req.profiler) {
|
req.profiler.start('windshaft-cartodb.delete_template');
|
||||||
req.profiler.start('windshaft-cartodb.delete_template');
|
|
||||||
}
|
|
||||||
|
|
||||||
var cdbuser = req.context.user;
|
var cdbuser = req.context.user;
|
||||||
var tpl_id;
|
var tpl_id;
|
||||||
@ -154,9 +150,7 @@ NamedMapsAdminController.prototype.destroy = function(req, res) {
|
|||||||
|
|
||||||
NamedMapsAdminController.prototype.list = function(req, res) {
|
NamedMapsAdminController.prototype.list = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if ( req.profiler ) {
|
req.profiler.start('windshaft-cartodb.get_template_list');
|
||||||
req.profiler.start('windshaft-cartodb.get_template_list');
|
|
||||||
}
|
|
||||||
|
|
||||||
var cdbuser = req.context.user;
|
var cdbuser = req.context.user;
|
||||||
|
|
||||||
|
@ -26,12 +26,14 @@ describe('tile stats', function() {
|
|||||||
var layergroupController = new LayergroupController();
|
var layergroupController = new LayergroupController();
|
||||||
|
|
||||||
var reqMock = {
|
var reqMock = {
|
||||||
|
profiler: { toJSONString:function() {} },
|
||||||
params: {
|
params: {
|
||||||
format: invalidFormat
|
format: invalidFormat
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var resMock = {
|
var resMock = {
|
||||||
status: function() { return this; },
|
status: function() { return this; },
|
||||||
|
set: function() {},
|
||||||
json: function() {},
|
json: function() {},
|
||||||
jsonp: function() {},
|
jsonp: function() {},
|
||||||
send: function() {}
|
send: function() {}
|
||||||
@ -54,12 +56,14 @@ describe('tile stats', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var reqMock = {
|
var reqMock = {
|
||||||
|
profiler: { toJSONString:function() {} },
|
||||||
params: {
|
params: {
|
||||||
format: validFormat
|
format: validFormat
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var resMock = {
|
var resMock = {
|
||||||
status: function() { return this; },
|
status: function() { return this; },
|
||||||
|
set: function() {},
|
||||||
json: function() {},
|
json: function() {},
|
||||||
jsonp: function() {},
|
jsonp: function() {},
|
||||||
send: function() {}
|
send: function() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user