From e67f7b0d0ec77dc34f5cec05873121ab55e736c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Mart=C3=ADnez?= Date: Mon, 22 Feb 2016 15:26:06 +0100 Subject: [PATCH] Drop old QueryTablesApi --- lib/cartodb/cache/named_map_provider_cache.js | 4 +- lib/cartodb/controllers/layergroup.js | 4 +- lib/cartodb/controllers/map.js | 17 +----- .../models/mapconfig/named_map_provider.js | 15 ++++- lib/cartodb/server.js | 6 +- test/acceptance/templates.js | 2 +- test/integration/overviews-metadata-api.js | 4 +- test/integration/query-tables-api.js | 56 ------------------- 8 files changed, 18 insertions(+), 90 deletions(-) delete mode 100644 test/integration/query-tables-api.js diff --git a/lib/cartodb/cache/named_map_provider_cache.js b/lib/cartodb/cache/named_map_provider_cache.js index 21c33142..0048cb63 100644 --- a/lib/cartodb/cache/named_map_provider_cache.js +++ b/lib/cartodb/cache/named_map_provider_cache.js @@ -7,11 +7,10 @@ var queue = require('queue-async'); var LruCache = require("lru-cache"); -function NamedMapProviderCache(templateMaps, pgConnection, userLimitsApi, queryTablesApi) { +function NamedMapProviderCache(templateMaps, pgConnection, userLimitsApi) { this.templateMaps = templateMaps; this.pgConnection = pgConnection; this.userLimitsApi = userLimitsApi; - this.queryTablesApi = queryTablesApi; this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps); @@ -30,7 +29,6 @@ NamedMapProviderCache.prototype.get = function(user, templateId, config, authTok this.templateMaps, this.pgConnection, this.userLimitsApi, - this.queryTablesApi, this.namedLayersAdapter, user, templateId, diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 6d393b27..7a450bd8 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -21,12 +21,11 @@ var QueryTables = require('node-cartodb-query-tables'); * @param {WidgetBackend} widgetBackend * @param {SurrogateKeysCache} surrogateKeysCache * @param {UserLimitsApi} userLimitsApi - * @param {QueryTablesApi} queryTablesApi * @param {LayergroupAffectedTables} layergroupAffectedTables * @constructor */ function LayergroupController(authApi, pgConnection, mapStore, tileBackend, previewBackend, attributesBackend, - widgetBackend, surrogateKeysCache, userLimitsApi, queryTablesApi, layergroupAffectedTables) { + widgetBackend, surrogateKeysCache, userLimitsApi, layergroupAffectedTables) { BaseController.call(this, authApi, pgConnection); this.pgConnection = pgConnection; @@ -37,7 +36,6 @@ function LayergroupController(authApi, pgConnection, mapStore, tileBackend, prev this.widgetBackend = widgetBackend; this.surrogateKeysCache = surrogateKeysCache; this.userLimitsApi = userLimitsApi; - this.queryTablesApi = queryTablesApi; this.layergroupAffectedTables = layergroupAffectedTables; } diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 87fa85ea..21ea9917 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -26,7 +26,6 @@ var MapConfigOverviewsAdapter = require('../models/mapconfig_overviews_adapter') * @param {TemplateMaps} templateMaps * @param {MapBackend} mapBackend * @param metadataBackend - * @param {QueryTablesApi} queryTablesApi * @param {OverviewsMetadataApi} overviewsMetadataApi * @param {SurrogateKeysCache} surrogateKeysCache * @param {UserLimitsApi} userLimitsApi @@ -34,7 +33,7 @@ var MapConfigOverviewsAdapter = require('../models/mapconfig_overviews_adapter') * @constructor */ function MapController(authApi, pgConnection, templateMaps, mapBackend, metadataBackend, - queryTablesApi, overviewsMetadataApi, + overviewsMetadataApi, surrogateKeysCache, userLimitsApi, layergroupAffectedTables) { BaseController.call(this, authApi, pgConnection); @@ -43,7 +42,6 @@ function MapController(authApi, pgConnection, templateMaps, mapBackend, metadata this.templateMaps = templateMaps; this.mapBackend = mapBackend; this.metadataBackend = metadataBackend; - this.queryTablesApi = queryTablesApi; this.overviewsMetadataApi = overviewsMetadataApi; this.surrogateKeysCache = surrogateKeysCache; this.userLimitsApi = userLimitsApi; @@ -214,7 +212,6 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn self.templateMaps, self.pgConnection, self.userLimitsApi, - self.queryTablesApi, self.namedLayersAdapter, cdbuser, req.params.template_id, @@ -319,18 +316,6 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la }, function getAffectedTablesAndLastUpdatedTime(err) { assert.ifError(err); - // if (hasCache) { - // var next = this; - // var affectedTables = self.layergroupAffectedTables.get(dbName, layergroupId); - // self.queryTablesApi.getLastUpdatedTime(username, affectedTables, function(err, lastUpdatedTime) { - // if (err) { - // return next(err); - // } - // return next(null, { affectedTables: affectedTables, lastUpdatedTime: lastUpdatedTime }); - // }); - // } else { - // self.queryTablesApi.getAffectedTablesAndLastUpdatedTime(username, sql, this); - //} step( function getConnection() { self.pgConnection.getConnection(username, this); diff --git a/lib/cartodb/models/mapconfig/named_map_provider.js b/lib/cartodb/models/mapconfig/named_map_provider.js index 0c86ce29..2d88c436 100644 --- a/lib/cartodb/models/mapconfig/named_map_provider.js +++ b/lib/cartodb/models/mapconfig/named_map_provider.js @@ -5,17 +5,17 @@ var dot = require('dot'); var step = require('step'); var MapConfig = require('windshaft').model.MapConfig; var templateName = require('../../backends/template_maps').templateName; +var QueryTables = require('node-cartodb-query-tables'); /** * @constructor * @type {NamedMapMapConfigProvider} */ -function NamedMapMapConfigProvider(templateMaps, pgConnection, userLimitsApi, queryTablesApi, namedLayersAdapter, +function NamedMapMapConfigProvider(templateMaps, pgConnection, userLimitsApi, namedLayersAdapter, owner, templateId, config, authToken, params) { this.templateMaps = templateMaps; this.pgConnection = pgConnection; this.userLimitsApi = userLimitsApi; - this.queryTablesApi = queryTablesApi; this.namedLayersAdapter = namedLayersAdapter; this.owner = owner; @@ -256,7 +256,16 @@ NamedMapMapConfigProvider.prototype.getAffectedTablesAndLastUpdatedTime = functi }, function getAffectedTables(err, sql) { assert.ifError(err); - self.queryTablesApi.getAffectedTablesAndLastUpdatedTime(self.owner, sql, this); + step( + function getConnection() { + self.pgConnection.getConnection(self.owner, this); + }, + function getAffectedTables(err, connection) { + assert.ifError(err); + QueryTables.getAffectedTablesFromQuery(connection, sql, this); + }, + this + ); }, function finish(err, result) { self.affectedTablesAndLastUpdate = result; diff --git a/lib/cartodb/server.js b/lib/cartodb/server.js index 9f9d9f69..39884850 100644 --- a/lib/cartodb/server.js +++ b/lib/cartodb/server.js @@ -19,7 +19,6 @@ var windshaft = require('windshaft'); var mapnik = windshaft.mapnik; var TemplateMaps = require('./backends/template_maps.js'); -var QueryTablesApi = require('./api/query_tables_api'); var OverviewsMetadataApi = require('./api/overviews_metadata_api'); var UserLimitsApi = require('./api/user_limits_api'); var AuthApi = require('./api/auth_api'); @@ -52,7 +51,6 @@ module.exports = function(serverOptions) { var metadataBackend = cartodbRedis({pool: redisPool}); var pgConnection = new PgConnection(metadataBackend); var pgQueryRunner = new PgQueryRunner(pgConnection); - var queryTablesApi = new QueryTablesApi(pgQueryRunner); var overviewsMetadataApi = new OverviewsMetadataApi(pgQueryRunner); var userLimitsApi = new UserLimitsApi(metadataBackend, { limits: { @@ -142,7 +140,7 @@ module.exports = function(serverOptions) { var layergroupAffectedTablesCache = new LayergroupAffectedTablesCache(); app.layergroupAffectedTablesCache = layergroupAffectedTablesCache; - var namedMapProviderCache = new NamedMapProviderCache(templateMaps, pgConnection, userLimitsApi, queryTablesApi); + var namedMapProviderCache = new NamedMapProviderCache(templateMaps, pgConnection, userLimitsApi); ['update', 'delete'].forEach(function(eventType) { templateMaps.on(eventType, namedMapProviderCache.invalidate.bind(namedMapProviderCache)); }); @@ -166,7 +164,6 @@ module.exports = function(serverOptions) { new windshaft.backend.Widget(), surrogateKeysCache, userLimitsApi, - queryTablesApi, layergroupAffectedTablesCache ).register(app); @@ -176,7 +173,6 @@ module.exports = function(serverOptions) { templateMaps, mapBackend, metadataBackend, - queryTablesApi, overviewsMetadataApi, surrogateKeysCache, userLimitsApi, diff --git a/test/acceptance/templates.js b/test/acceptance/templates.js index 4b53e0a6..cf2624c4 100644 --- a/test/acceptance/templates.js +++ b/test/acceptance/templates.js @@ -1477,7 +1477,7 @@ describe('template_api', function() { // See https://github.com/CartoDB/Windshaft-cartodb/issues/176 helper.checkCache(res); var expectedSurrogateKey = [ - new QueryTables.DatabaseTableEntry([{dbname: 'test_windshaft_cartodb_user_1_db', schema_name: 'public', + new QueryTables.DatabaseTablesEntry([{dbname: 'test_windshaft_cartodb_user_1_db', schema_name: 'public', table_name: 'test_table_private_1'}]).key(), new NamedMapsCacheEntry('localhost', template_acceptance_open.name).key() ].join(' '); diff --git a/test/integration/overviews-metadata-api.js b/test/integration/overviews-metadata-api.js index 6c054d1e..f1182a6c 100644 --- a/test/integration/overviews-metadata-api.js +++ b/test/integration/overviews-metadata-api.js @@ -7,20 +7,18 @@ var cartodbRedis = require('cartodb-redis'); var PgConnection = require('../../lib/cartodb/backends/pg_connection'); var PgQueryRunner = require('../../lib/cartodb/backends/pg_query_runner'); -var QueryTablesApi = require('../../lib/cartodb/api/query_tables_api'); var OverviewsMetadataApi = require('../../lib/cartodb/api/overviews_metadata_api'); describe('OverviewsMetadataApi', function() { - var queryTablesApi, overviewsMetadataApi; + var overviewsMetadataApi; before(function() { var redisPool = new RedisPool(global.environment.redis); var metadataBackend = cartodbRedis({pool: redisPool}); var pgConnection = new PgConnection(metadataBackend); var pgQueryRunner = new PgQueryRunner(pgConnection); - queryTablesApi = new QueryTablesApi(pgQueryRunner); overviewsMetadataApi = new OverviewsMetadataApi(pgQueryRunner); }); diff --git a/test/integration/query-tables-api.js b/test/integration/query-tables-api.js deleted file mode 100644 index 93ca0a07..00000000 --- a/test/integration/query-tables-api.js +++ /dev/null @@ -1,56 +0,0 @@ -require('../support/test_helper'); - -var assert = require('assert'); - -var RedisPool = require('redis-mpool'); -var cartodbRedis = require('cartodb-redis'); - -var PgConnection = require('../../lib/cartodb/backends/pg_connection'); -var PgQueryRunner = require('../../lib/cartodb/backends/pg_query_runner'); -var QueryTablesApi = require('../../lib/cartodb/api/query_tables_api'); - - -describe('QueryTablesApi', function() { - - var queryTablesApi; - - before(function() { - var redisPool = new RedisPool(global.environment.redis); - var metadataBackend = cartodbRedis({pool: redisPool}); - var pgConnection = new PgConnection(metadataBackend); - var pgQueryRunner = new PgQueryRunner(pgConnection); - queryTablesApi = new QueryTablesApi(pgQueryRunner); - }); - - // Check test/support/sql/windshaft.test.sql to understand where the values come from. - - it('should return an object with affected tables array and last updated time', function(done) { - var query = 'select * from test_table'; - queryTablesApi.getAffectedTablesAndLastUpdatedTime('localhost', query, function(err, result) { - assert.ok(!err, err); - assert.deepEqual(result, { - affectedTables: [{dbname: "test_windshaft_cartodb_user_1_db", schema_name: "public", - "table_name": 'test_table', updated_at: new Date(1234567890123)}], - lastUpdatedTime: 1234567890123 - }); - - done(); - }); - }); - - it('should work with private tables', function(done) { - var query = 'select * from test_table_private_1'; - queryTablesApi.getAffectedTablesAndLastUpdatedTime('localhost', query, function(err, result) { - assert.ok(!err, err); - - assert.deepEqual(result, { - affectedTables: [{dbname: "test_windshaft_cartodb_user_1_db", schema_name: "public", - "table_name": 'test_table_private_1', updated_at: new Date(1234567890123)}], - lastUpdatedTime: 1234567890123 - }); - - done(); - }); - }); - -});