From b11b872b755ce4204befbd7da1ac593ceaa808a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 2 Nov 2017 11:29:43 +0100 Subject: [PATCH] Remove step requirement --- lib/cartodb/controllers/map.js | 46 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 7478ce49..372dd567 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -1,6 +1,4 @@ var _ = require('underscore'); -var assert = require('assert'); -var step = require('step'); var windshaft = require('windshaft'); var QueryTables = require('cartodb-query-tables'); @@ -346,41 +344,37 @@ MapController.prototype.augmentLayergroupData = function (req, res, callback) { callback(); }; -MapController.prototype.getAffectedTables = function (req, res, callback) { - const self = this; +MapController.prototype.getAffectedTables = function (req, res, next) { const { dbname, layergroup, user, mapconfig } = res.locals; - var sql = []; - mapconfig.getLayers().forEach(function(layer) { - sql.push(layer.options.sql); - if (layer.options.affected_tables) { - layer.options.affected_tables.map(function(table) { - sql.push('SELECT * FROM ' + table + ' LIMIT 0'); - }); + this.pgConnection.getConnection(user, (err, connection) => { + if (err) { + return next(err); } - }); - step( - function getPgConnection() { - self.pgConnection.getConnection(user, this); - }, - function getAffectedTablesAndLastUpdatedTime(err, connection) { - assert.ifError(err); - QueryTables.getAffectedTablesFromQuery(connection, sql.join(';'), this); - }, - function handleAffectedTablesAndLastUpdatedTime(err, affectedTables) { + const sql = []; + mapconfig.getLayers().forEach(function(layer) { + sql.push(layer.options.sql); + if (layer.options.affected_tables) { + layer.options.affected_tables.map(function(table) { + sql.push('SELECT * FROM ' + table + ' LIMIT 0'); + }); + } + }); + + QueryTables.getAffectedTablesFromQuery(connection, sql.join(';'), (err, affectedTables) => { if (err) { - return callback(err); + return next(err); } // feed affected tables cache so it can be reused from, for instance, layergroup controller - self.layergroupAffectedTables.set(dbname, layergroup.layergroupId, affectedTables); + this.layergroupAffectedTables.set(dbname, layergroup.layergroupId, affectedTables); res.locals.affectedTables = affectedTables; - callback(); - } - ); + next(); + }); + }); }; MapController.prototype.setCacheChannel = function (req, res, callback) {