diff --git a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js index 49988aa8..6a71435e 100644 --- a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js +++ b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js @@ -94,8 +94,8 @@ function addStat(queries, ctx, type, zoom, query, assign, assignDefault=null) { ) ); } -function firstPhaseQueries(queries, ctx) { - // estimatedFeatureCount + +function _estimatedFeatureCount(queries, ctx) { if (queries.results.estimatedFeatureCount === undefined) { // This is always computed; a default value of -1 is used in case of error addStat( @@ -107,8 +107,9 @@ function firstPhaseQueries(queries, ctx) { () => queries.results.estimatedFeatureCount = -1 ); } +} - // featureCount +function _featureCount(queries, ctx) { if (ctx.metaOptions.featureCount) { // TODO: if ctx.metaOptions.columnStats we can combine this with column stats query addStat( @@ -119,8 +120,9 @@ function firstPhaseQueries(queries, ctx) { res => queries.results.featureCount = res.rows[0].rows ); } +} - // aggrFeatureCount +function _aggrFeatureCount(queries, ctx) { if (ctx.metaOptions.hasOwnProperty('aggrFeatureCount')) { // We expect as zoom level as the value of aggrFeatureCount // TODO: it'd be nice to admit an array of zoom levels to @@ -133,8 +135,9 @@ function firstPhaseQueries(queries, ctx) { res => queries.results.aggrfeatureCount = res.rows[0].rows ); } +} - // geometryType +function _geometryType(queries, ctx) { if (ctx.metaOptions.geometryType && queries.results.geometryType === undefined) { const geometryColumn = AggregationMapConfig.getAggregationGeometryColumn(); addStat( @@ -145,8 +148,9 @@ function firstPhaseQueries(queries, ctx) { res => queries.results.geometryType = res.rows[0].geom_type ); } +} - // columns (names & types) +function _columns(queries, ctx) { if (ctx.metaOptions.columns || ctx.metaOptions.columnStats) { // note: post-aggregation columns are in layer.options.columns when aggregation is present addStat( @@ -159,8 +163,15 @@ function firstPhaseQueries(queries, ctx) { } } -function secondPhaseQueries(queries, ctx) { - // sample +function firstPhaseQueries(queries, ctx) { + _estimatedFeatureCount(queries, ctx); + _featureCount(queries, ctx); + _aggrFeatureCount(queries, ctx); + _geometryType(queries, ctx); + _columns(queries, ctx); +} + +function _sample(queries, ctx) { if (ctx.metaOptions.sample) { const numRows = queries.results.featureCount === undefined ? queries.results.estimatedFeatureCount : @@ -174,8 +185,9 @@ function secondPhaseQueries(queries, ctx) { res => queries.results.sample = res.rows ); } +} - // columnStats +function _columnStats(queries, ctx) { if (ctx.metaOptions.columnStats) { let aggr = []; Object.keys(queries.results.columns).forEach(name => { @@ -210,7 +222,11 @@ function secondPhaseQueries(queries, ctx) { } ); } +} +function secondPhaseQueries(queries, ctx) { + _sample(queries, ctx); + _columnStats(queries, ctx); } // This is adapted from SQL API: