From ef9e9f8c78938b6e0d9739caa53164c6d6ffa23a Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Tue, 26 Jan 2016 11:38:21 +0100 Subject: [PATCH] Adapt to changes in CDB_Overviews SQL function Now data for multiple tables is obtained in one call, simplifying the use of this function. Also base table is returned as an oid, so we now have the overview base table names with schema only when needed. --- lib/cartodb/api/overviews_api.js | 96 ++++++++----------- test/acceptance/multilayer_server.js | 2 +- test/acceptance/overviews.js | 14 +-- .../mapconfig_overviews_adapter.js | 14 +-- test/integration/overviews-api.js | 2 +- test/support/sql/CDB_Overviews.sql | 10 +- 6 files changed, 61 insertions(+), 77 deletions(-) diff --git a/lib/cartodb/api/overviews_api.js b/lib/cartodb/api/overviews_api.js index 2a677210..305d6422 100644 --- a/lib/cartodb/api/overviews_api.js +++ b/lib/cartodb/api/overviews_api.js @@ -1,61 +1,45 @@ -var queue = require('queue-async'); -var QueryTablesApi = require('./query_tables_api'); - -function OverviewsApi(pgQueryRunner) { - if (pgQueryRunner.pgQueryRunner !== undefined) { - this.queryTablesApi = pgQueryRunner; - this.pgQueryRunner = this.queryTablesApi.pgQueryRunner; - } else { - this.pgQueryRunner = pgQueryRunner; - this.queryTablesApi = new QueryTablesApi(pgQueryRunner); - } +// TODO: use pgQueryRunner parameter directly +function OverviewsApi(queryTablesApi) { + this.pgQueryRunner = queryTablesApi.pgQueryRunner; } module.exports = OverviewsApi; -OverviewsApi.prototype.getOverviewsMetadata = function (username, sql, callback) { - var self = this; - this.queryTablesApi.getAffectedTablesInQuery(username, sql, function(err, tableNames){ - if (err) { - callback(err); - } else { - var parallelism = 2; - var q = queue(parallelism); - - tableNames.forEach(function(tableName) { - q.defer(function(done){ - var query = "SELECT * FROM CDB_Overviews('" + tableName + "');"; - self.pgQueryRunner.run(username, query, function handleOverviewsRows(err, rows) { - if (err){ - var msg = err.message ? err.message : err; - done(new Error('could not get overviews metadata: ' + msg)); - return; - } - done(null, [tableName, rows]); - }); - }); - }); - - var metadata = {}; - q.awaitAll(function(err, results){ - if (err) { - return callback(err); - } else { - results.forEach(function(table_rows) { - var tableName = table_rows[0]; - var rows = table_rows[1]; - if ( rows.length > 0 ) { - var table_metadata = {}; - for ( var i=0; i