diff --git a/lib/cartodb/api/auth_api.js b/lib/cartodb/api/auth_api.js index 68533fe9..484d66b1 100644 --- a/lib/cartodb/api/auth_api.js +++ b/lib/cartodb/api/auth_api.js @@ -95,9 +95,7 @@ AuthApi.prototype.authorize = function(req, callback) { self.authorizedByAPIKey(user, req, this); }, function checkApiKey(err, authorized){ - if (req.profiler) { - req.profiler.done('authorizedByAPIKey'); - } + req.profiler.done('authorizedByAPIKey'); assert.ifError(err); // 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) { - if (req.profiler) { - req.profiler.done('setDBAuth'); - } + req.profiler.done('setDBAuth'); callback(err, true); // authorized (or error) }); } diff --git a/lib/cartodb/controllers/base.js b/lib/cartodb/controllers/base.js index 4ce9af17..90934b7d 100644 --- a/lib/cartodb/controllers/base.js +++ b/lib/cartodb/controllers/base.js @@ -61,9 +61,7 @@ BaseController.prototype.req2params = function(req, callback){ lzmaWorker.decompress( lzma, function(result) { - if (req.profiler) { - req.profiler.done('lzma'); - } + req.profiler.done('lzma'); try { delete req.query.lzma; _.extend(req.query, JSON.parse(result)); @@ -115,18 +113,14 @@ BaseController.prototype.req2params = function(req, callback){ // bring all query values onto req.params object _.extend(req.params, req.query); - if (req.profiler) { - req.profiler.done('req2params.setup'); - } + req.profiler.done('req2params.setup'); step( function getPrivacy(){ self.authApi.authorize(req, this); }, function validateAuthorization(err, authorized) { - if (req.profiler) { - req.profiler.done('authorize'); - } + req.profiler.done('authorize'); assert.ifError(err); if(!authorized) { 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); } - if (req.profiler) { - res.set('X-Tiler-Profiler', req.profiler.toJSONString()); - } + res.set('X-Tiler-Profiler', req.profiler.toJSONString()); if (headers) { res.set(headers); @@ -187,14 +179,12 @@ BaseController.prototype.send = function(req, res, body, status, headers) { res.send(body); } - if (req.profiler) { - try { - // May throw due to dns, see - // See http://github.com/CartoDB/Windshaft/issues/166 - req.profiler.sendStats(); - } catch (err) { - debug("error sending profiling stats: " + err); - } + try { + // May throw due to dns, see + // See http://github.com/CartoDB/Windshaft/issues/166 + req.profiler.sendStats(); + } catch (err) { + debug("error sending profiling stats: " + err); } }; // jshint maxcomplexity:6 diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 417cf266..cfd9e0d6 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -87,9 +87,7 @@ MapController.prototype.createPost = 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) { if (!req.is('application/json')) { @@ -100,9 +98,7 @@ MapController.prototype.instantiate = 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) { var err = null; @@ -303,9 +299,7 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la // take place before proceeding. Error will be logged // asynchronously this.metadataBackend.incMapviewCount(username, mapconfig.obj().stat_tag, function(err) { - if (req.profiler) { - req.profiler.done('incMapviewCount'); - } + req.profiler.done('incMapviewCount'); if ( 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); }, function handleAffectedTablesAndLastUpdatedTime(err, result) { - if (req.profiler) { - req.profiler.done('queryTablesAndLastUpdated'); - } + req.profiler.done('queryTablesAndLastUpdated'); assert.ifError(err); // feed affected tables cache so it can be reused from, for instance, layergroup controller self.layergroupAffectedTables.set(dbName, layergroupId, result); diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index 4d22aeea..f8f9b89c 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -100,9 +100,7 @@ NamedMapsController.prototype.tile = function(req, res) { self.tileBackend.getTile(namedMapProvider, req.params, this); }, function handleImage(err, tile, headers, stats) { - if (req.profiler) { - req.profiler.add(stats); - } + req.profiler.add(stats); if (err) { self.sendError(req, res, err, 'NAMED_MAP_TILE'); } else { @@ -176,10 +174,8 @@ NamedMapsController.prototype.staticMap = function(req, res) { }); }, function handleImage(err, image, headers, stats) { - if (req.profiler) { - req.profiler.done('render-' + format); - req.profiler.add(stats || {}); - } + req.profiler.done('render-' + format); + req.profiler.add(stats || {}); if (err) { self.sendError(req, res, err, 'STATIC_VIZ_MAP'); diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 3d201049..08ad5322 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -91,9 +91,7 @@ NamedMapsAdminController.prototype.update = function(req, res) { NamedMapsAdminController.prototype.retrieve = function(req, res) { 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 tpl_id; @@ -127,9 +125,7 @@ NamedMapsAdminController.prototype.retrieve = function(req, res) { NamedMapsAdminController.prototype.destroy = function(req, res) { 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 tpl_id; @@ -154,9 +150,7 @@ NamedMapsAdminController.prototype.destroy = function(req, res) { NamedMapsAdminController.prototype.list = function(req, res) { 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; diff --git a/test/unit/cartodb/ported/tile_stats.test.js b/test/unit/cartodb/ported/tile_stats.test.js index e5ad622d..45b1fa29 100644 --- a/test/unit/cartodb/ported/tile_stats.test.js +++ b/test/unit/cartodb/ported/tile_stats.test.js @@ -26,12 +26,14 @@ describe('tile stats', function() { var layergroupController = new LayergroupController(); var reqMock = { + profiler: { toJSONString:function() {} }, params: { format: invalidFormat } }; var resMock = { status: function() { return this; }, + set: function() {}, json: function() {}, jsonp: function() {}, send: function() {} @@ -54,12 +56,14 @@ describe('tile stats', function() { } }); var reqMock = { + profiler: { toJSONString:function() {} }, params: { format: validFormat } }; var resMock = { status: function() { return this; }, + set: function() {}, json: function() {}, jsonp: function() {}, send: function() {}