From 367ca399c8a507695ccdc065ed94bb60b416e13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 11 Mar 2019 18:53:47 +0100 Subject: [PATCH] Improve readability --- lib/cartodb/backends/cluster.js | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/cartodb/backends/cluster.js b/lib/cartodb/backends/cluster.js index 87b3b27d..ab663997 100644 --- a/lib/cartodb/backends/cluster.js +++ b/lib/cartodb/backends/cluster.js @@ -24,6 +24,7 @@ module.exports = class ClusterBackend { const { user, layer: layerIndex } = params; const mapConfig = new AggregationMapConfig(user, _mapConfig.obj(), pg); const layer = mapConfig.getLayer(layerIndex); + let { aggregation } = params; try { @@ -44,35 +45,35 @@ module.exports = class ClusterBackend { return callback(error); } - const query = layer.options.sql_raw; - const resolution = layer.options.aggregation.resolution || 1; + params.aggregation = aggregation; - getColumnsName(pg, query, (err, columns) => { - if (err) { - return callback(err); - } - - const { zoom, clusterId } = params; - - getClusterFeatures(pg, zoom, clusterId, columns, query, resolution, aggregation, (err, features) => { - if (err) { - return callback(err); - } - - return callback(null, features); - }); - }); + getFeatures(pg, layer, params, callback); }); } }; +function getFeatures (pg, layer, params, callback) { + const query = layer.options.sql_raw; + const resolution = layer.options.aggregation.resolution || 1; + + getColumnsName(pg, query, (err, columns) => { + if (err) { + return callback(err); + } + + const { zoom, clusterId, aggregation } = params; + + getClusterFeatures(pg, zoom, clusterId, columns, query, resolution, aggregation, callback); + }); +} + const SKIP_COLUMNS = { 'the_geom': true, 'the_geom_webmercator': true }; function getColumnsName (pg, query, callback) { - const sql = limitedQuery({ + const sql = schemaQuery({ query: query }); @@ -126,7 +127,7 @@ function getClusterFeatures (pg, zoom, clusterId, columns, query, resolution, ag } , true); // use read-only transaction } -const limitedQuery = ctx => `SELECT * FROM (${ctx.query}) __cdb_schema LIMIT 0`; +const schemaQuery = ctx => `SELECT * FROM (${ctx.query}) __cdb_schema LIMIT 0`; const clusterFeaturesQuery = ctx => ` WITH _cdb_params AS (