From a11cc28dc7ee1ae3cbda97cf1e3ec9e19eb7f7c7 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 23 May 2016 18:59:23 +0200 Subject: [PATCH] Use context for analyses results --- lib/cartodb/controllers/map.js | 20 ++++++++++--------- .../adapter/analysis-mapconfig-adapter.js | 4 +++- .../mapconfig/provider/named-map-provider.js | 20 ++++++++++--------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index c573a298..5f7d0894 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -134,7 +134,6 @@ MapController.prototype.create = function(req, res, prepareConfigFn) { var self = this; var mapConfig; - var analysesResults = []; var user = req.context.user; var context = {}; @@ -144,11 +143,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) { self.req2params(req, this); }, prepareConfigFn, - function prepareSqlWrap(err, requestMapConfig) { - assert.ifError(err); - self.sqlWrapMapConfigAdapter.getMapConfig(user, requestMapConfig, req.params, context, this); - }, - function prepareAnalysisLayers(err, requestMapConfig) { + function prepareAdapterMapConfig(err, requestMapConfig) { assert.ifError(err); context.analysisConfiguration = { db: { @@ -163,12 +158,19 @@ MapController.prototype.create = function(req, res, prepareConfigFn) { apiKey: req.params.api_key } }; + return requestMapConfig; + }, + function prepareSqlWrap(err, requestMapConfig) { + assert.ifError(err); + self.sqlWrapMapConfigAdapter.getMapConfig(user, requestMapConfig, req.params, context, this); + }, + function prepareAnalysisLayers(err, requestMapConfig) { + assert.ifError(err); self.analysisMapConfigAdapter.getMapConfig(user, requestMapConfig, req.params, context, this); }, - function beforeLayergroupCreate(err, requestMapConfig, _analysesResults) { + function beforeLayergroupCreate(err, requestMapConfig) { assert.ifError(err); var next = this; - analysesResults = _analysesResults; self.namedLayersAdapter.getMapConfig(user, requestMapConfig, req.params, context, function(err, requestMapConfig, datasource) { if (err) { @@ -182,7 +184,6 @@ MapController.prototype.create = function(req, res, prepareConfigFn) { function addOverviewsInformation(err, requestMapConfig, datasource) { assert.ifError(err); var next = this; - context.analysesResults = analysesResults; self.overviewsAdapter.getMapConfig(req.context.user, requestMapConfig, req.params, context, function(err, requestMapConfig) { if (err) { @@ -218,6 +219,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) { }, function afterLayergroupCreate(err, layergroup) { assert.ifError(err); + var analysesResults = context.analysesResults || []; self.afterLayergroupCreate(req, res, mapConfig, analysesResults, layergroup, this); }, function finish(err, layergroup) { diff --git a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js index 0b61be80..c48de8a4 100644 --- a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js @@ -178,7 +178,9 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi return callback(missingNodesErrors); } - return callback(null, requestMapConfig, analysesResults); + context.analysesResults = analysesResults; + + return callback(null, requestMapConfig); }); }; diff --git a/lib/cartodb/models/mapconfig/provider/named-map-provider.js b/lib/cartodb/models/mapconfig/provider/named-map-provider.js index 453fcab9..da17c93a 100644 --- a/lib/cartodb/models/mapconfig/provider/named-map-provider.js +++ b/lib/cartodb/models/mapconfig/provider/named-map-provider.js @@ -100,11 +100,7 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) { assert.ifError(err); return self.templateMaps.instance(self.template, templateParams); }, - function prepareSqlWrap(err, requestMapConfig) { - assert.ifError(err); - self.sqlWrapMapConfigAdapter.getMapConfig(user, requestMapConfig, rendererParams, context, this); - }, - function prepareAnalysisLayers(err, requestMapConfig) { + function prepareAdapterMapConfig(err, requestMapConfig) { assert.ifError(err); context.analysisConfiguration = { db: { @@ -119,13 +115,20 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) { apiKey: apiKey } }; - + return requestMapConfig; + }, + function prepareSqlWrap(err, requestMapConfig) { + assert.ifError(err); + self.sqlWrapMapConfigAdapter.getMapConfig(user, requestMapConfig, rendererParams, context, this); + }, + function prepareAnalysisLayers(err, requestMapConfig) { + assert.ifError(err); self.analysisMapConfigAdapter.getMapConfig(user, requestMapConfig, rendererParams, context, this); }, - function prepareLayergroup(err, _mapConfig, analysesResults) { + function prepareLayergroup(err, _mapConfig) { assert.ifError(err); var next = this; - self.analysesResults = analysesResults || []; + self.analysesResults = context.analysesResults || []; self.namedLayersAdapter.getMapConfig(self.owner, _mapConfig, rendererParams, context, function(err, _mapConfig, datasource) { if (err) { @@ -139,7 +142,6 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) { function addOverviewsInformation(err, _mapConfig, datasource) { assert.ifError(err); var next = this; - context.analysesResults = self.analysesResults; self.overviewsAdapter.getMapConfig(self.owner, _mapConfig, rendererParams, context, function(err, _mapConfig) { if (err) {