diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 01fe461b..d4d24722 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -76,21 +76,7 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal this.prepareContext, initProfiler(isTemplateInstantiation), checkJsonContentType(), - useTemplate ? - checkInstantiteLayergroup() : - checkCreateLayergroup(), - useTemplate ? - getTemplate( - this.templateMaps, - this.pgConnection, - this.metadataBackend, - this.userLimitsApi, - this.mapConfigAdapter - ) : - prepareAdapterMapConfig(this.mapConfigAdapter), - useTemplate ? - instantiateLayergroup(this.mapBackend, this.userLimitsApi) : - createLayergroup (this.mapBackend, this.userLimitsApi), + this.getCreateMapMiddlewares(useTemplate), incrementMapViewCount(this.metadataBackend), augmentLayergroupData(), getAffectedTables(this.pgConnection, this.layergroupAffectedTables), @@ -111,6 +97,28 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal ]; }; +MapController.prototype.getCreateMapMiddlewares = function (useTemplate) { + if (useTemplate) { + return [ + checkInstantiteLayergroup(), + getTemplate( + this.templateMaps, + this.pgConnection, + this.metadataBackend, + this.userLimitsApi, + this.mapConfigAdapter + ), + instantiateLayergroup(this.mapBackend, this.userLimitsApi) + ]; + } + + return [ + checkCreateLayergroup(), + prepareAdapterMapConfig(this.mapConfigAdapter), + createLayergroup (this.mapBackend, this.userLimitsApi) + ]; +} + function initProfiler (isTemplateInstantiation) { const operation = isTemplateInstantiation ? 'instance_template' : 'createmap';