diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 182fcff5..e10a59c5 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -516,22 +516,28 @@ function getAffectedTables (layergroupAffectedTables, pgConnection) { return next(); } + 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`); + }); + } + }); + + const sql = queries.length ? queries.join(';') : null; + + if (!sql) { + return next(); + } + pgConnection.getConnection(user, (err, connection) => { if (err) { global.logger.warn('ERROR generating cache channel:', err); return next(); } - 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) => { req.profiler.done('getAffectedTablesFromQuery'); if (err) {