From 38e55367b1ec179da31b6b9582c3d9c3bb0f0bfc Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 21 May 2018 11:44:52 +0200 Subject: [PATCH] Revert error behaviour for estimatedFeatureCount Keep current production behavior of ignoreing errors when computing this stat and returning -1. This is done as to no introduce any instability in production at the moment. --- .../backends/layer-stats/mapnik-layer-stats.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js index e3d11070..9ce411ed 100644 --- a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js +++ b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js @@ -34,11 +34,16 @@ MapnikLayerStats.prototype.is = function (type) { return this._types[type] ? this._types[type] : false; }; -function queryPromise(dbConnection, query, adaptResults) { +function queryPromise(dbConnection, query, adaptResults, errorHandler) { return new Promise(function(resolve, reject) { dbConnection.query(query, function (err, res) { if (err) { - reject(err); + if (errorHandler) { + errorHandler(err); + } + else { + reject(err); + } } else { resolve(adaptResults(res)); @@ -71,11 +76,11 @@ function _getSQL(ctx, query, type='pre', zoom=0) { } function _estimatedFeatureCount(ctx) { - // TODO: restore -1 on errors behavior? return queryPromise( ctx.dbConnection, _getSQL(ctx, queryUtils.getQueryRowEstimation), - res => ({ estimatedFeatureCount: res.rows[0].rows }) + res => ({ estimatedFeatureCount: res.rows[0].rows }), + () => ({ estimatedFeatureCount: -1 }) ); }