diff --git a/lib/cartodb/models/aggregation/aggregation-mapconfig.js b/lib/cartodb/models/aggregation/aggregation-mapconfig.js index 7966693e..95ae1641 100644 --- a/lib/cartodb/models/aggregation/aggregation-mapconfig.js +++ b/lib/cartodb/models/aggregation/aggregation-mapconfig.js @@ -38,7 +38,7 @@ module.exports = class AggregationMapConfig extends MapConfig { return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType); } - constructor (config, connection, datasource) { + constructor (user, config, connection, datasource) { super(config, datasource); const validate = aggregationValidator(this); @@ -51,7 +51,8 @@ module.exports = class AggregationMapConfig extends MapConfig { validate('threshold', positiveNumberValidator); validate('columns', aggregationColumnsValidator); - this.connection = connection; + this.user = user; + this.pgConnection = connection; } getAggregatedQuery (index) { @@ -128,20 +129,41 @@ module.exports = class AggregationMapConfig extends MapConfig { const limitedQuery = ctx => `SELECT * FROM (${ctx.query}) __cdb_schema LIMIT 0`; const layer = this.getLayer(index); - this.connection.query(limitedQuery({ query: layer.options.sql }), (err, result) => { + this.pgConnection.getConnection(this.user, (err, connection) => { if (err) { return callback(err); } - let columns = result.fields || []; + const sql = limitedQuery({ query: layer.options.sql }); - columns = columns.map(({ name, type }) => ({ name, type })); + connection.query(sql, (err, result) => { + if (err) { + return callback(err); + } - if (skipGeoms) { - columns = columns.filter((column) => !geomColumns.includes(column)); - } + let columns = result.fields || []; - return callback(err, columns); + columns = columns.map(({ name, type }) => ({ name, type })); + + if (skipGeoms) { + columns = columns.filter((column) => !geomColumns.includes(column)); + } + + return callback(err, columns); + }); }); } + + isDefaultAggregation (index) { + const aggregation = this.getAggregation(index); + return !aggregation || ( + !aggregation.placement && + this._isEmptyParameter(aggregation.columns) && + this._isEmptyParameter(aggregation.dimensions) + ); + } + + _isEmptyParameter (parameter) { + return !parameter || Object.keys(parameter).length === 0; + } }; diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index 99f68a0f..1540faf7 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -20,7 +20,7 @@ module.exports = class AggregationMapConfigAdapter { let mapConfig; try { - mapConfig = new AggregationMapConfig(requestMapConfig); + mapConfig = new AggregationMapConfig(user, requestMapConfig, this.pgConnection); } catch (err) { return callback(err); } @@ -100,9 +100,18 @@ module.exports = class AggregationMapConfigAdapter { layer.options.sql = aggregationSql; - const aggregatedColumns = mapConfig.getAggregatedColumns(index); + if (mapConfig.isDefaultAggregation(index)) { + const skipGeoms = true; + mapConfig.getLayerColumns(index, skipGeoms, (err, columns) => { + if (err) { + return reject(err); + } - layer.options.columns = aggregatedColumns; + layer.options.columns = columns; + + return resolve({ layer, index, adapted: shouldAdapt }); + }); + } } return resolve({ layer, index, adapted: shouldAdapt }); diff --git a/package.json b/package.json index dd210fc0..669ec59c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "step-profiler": "~0.3.0", "turbo-carto": "0.20.2", "underscore": "~1.6.0", - "windshaft": "4.1.0", + "windshaft": "cartodb/windshaft#pg-mvt-do-not-filter-columns", "yargs": "~5.0.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 78e663f0..a8d4808b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -244,14 +244,6 @@ carto@0.16.3: semver "^5.1.0" yargs "^4.2.0" -carto@CartoDB/carto#0.15.1-cdb1: - version "0.15.1-cdb1" - resolved "https://codeload.github.com/CartoDB/carto/tar.gz/8050ec843f1f32a6469e5d1cf49602773015d398" - dependencies: - mapnik-reference "~6.0.2" - optimist "~0.6.0" - underscore "~1.6.0" - carto@cartodb/carto#0.15.1-cdb3: version "0.15.1-cdb3" resolved "https://codeload.github.com/cartodb/carto/tar.gz/945f5efb74fd1af1f5e1f69f409f9567f94fb5a7" @@ -260,6 +252,14 @@ carto@cartodb/carto#0.15.1-cdb3: optimist "~0.6.0" underscore "1.8.3" +"carto@github:cartodb/carto#0.15.1-cdb1": + version "0.15.1-cdb1" + resolved "https://codeload.github.com/cartodb/carto/tar.gz/8050ec843f1f32a6469e5d1cf49602773015d398" + dependencies: + mapnik-reference "~6.0.2" + optimist "~0.6.0" + underscore "~1.6.0" + cartocolor@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/cartocolor/-/cartocolor-4.0.0.tgz#841a3222d8b5b22718d9d545b1e5b972cb26eb36" @@ -2392,9 +2392,9 @@ window-size@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.2.0.tgz#b4315bb4214a3d7058ebeee892e13fa24d98b075" -windshaft@4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/windshaft/-/windshaft-4.1.0.tgz#dc17c8369570c305171d1ab5ca130369bba04d58" +windshaft@cartodb/windshaft#pg-mvt-do-not-filter-columns: + version "4.1.1" + resolved "https://codeload.github.com/cartodb/windshaft/tar.gz/2de4e21b41787acd1630193fdd42c308815bfee5" dependencies: abaculus cartodb/abaculus#2.0.3-cdb1 canvas cartodb/node-canvas#1.6.2-cdb2