From 233f9698f3e51f665eefd755e53f24b0b8ccec9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Fri, 6 Apr 2018 12:59:53 +0200 Subject: [PATCH] fix affectedtables cache --- .../provider/create-layergroup-provider.js | 25 +++++++++++++----- .../mapconfig/provider/map-store-provider.js | 26 ++++++++++++++----- .../mapconfig/provider/named-map-provider.js | 25 +++++++++++++----- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/lib/cartodb/models/mapconfig/provider/create-layergroup-provider.js b/lib/cartodb/models/mapconfig/provider/create-layergroup-provider.js index b3b3f191..1f19d395 100644 --- a/lib/cartodb/models/mapconfig/provider/create-layergroup-provider.js +++ b/lib/cartodb/models/mapconfig/provider/create-layergroup-provider.js @@ -58,7 +58,7 @@ CreateLayergroupMapConfigProvider.prototype.filter = MapStoreMapConfigProvider.p CreateLayergroupMapConfigProvider.prototype.createKey = MapStoreMapConfigProvider.prototype.createKey; -CreateLayergroupMapConfigProvider.prototype.getAffectedTables = function (callback) { +CreateLayergroupMapConfigProvider.prototype.createAffectedTables = function (callback) { this.getMapConfig((err, mapConfig) => { if (err) { return callback(err); @@ -67,11 +67,6 @@ CreateLayergroupMapConfigProvider.prototype.getAffectedTables = function (callba const { dbname } = this.params; const token = mapConfig.id(); - if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { - const affectedTables = this.affectedTablesCache.get(dbname, token); - return callback(null, affectedTables); - } - const queries = []; this.mapConfig.getLayers().forEach(layer => { @@ -106,3 +101,21 @@ CreateLayergroupMapConfigProvider.prototype.getAffectedTables = function (callba }); }); }; + +CreateLayergroupMapConfigProvider.prototype.getAffectedTables = function (callback) { + this.getMapConfig((err, mapConfig) => { + if (err) { + return callback(err); + } + + const { dbname } = this.params; + const token = mapConfig.id(); + + if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { + const affectedTables = this.affectedTablesCache.get(dbname, token); + return callback(null, affectedTables); + } + + return this.createAffectedTables(callback); + }); +}; diff --git a/lib/cartodb/models/mapconfig/provider/map-store-provider.js b/lib/cartodb/models/mapconfig/provider/map-store-provider.js index f89a79ce..d9f9da83 100644 --- a/lib/cartodb/models/mapconfig/provider/map-store-provider.js +++ b/lib/cartodb/models/mapconfig/provider/map-store-provider.js @@ -89,7 +89,7 @@ MapStoreMapConfigProvider.prototype.createKey = function(base) { return (base) ? baseKeyTpl(tplValues) : rendererKeyTpl(tplValues); }; -MapStoreMapConfigProvider.prototype.getAffectedTables = function(callback) { +MapStoreMapConfigProvider.prototype.createAffectedTables = function(callback) { this.getMapConfig((err, mapConfig) => { if (err) { return callback(err); @@ -98,12 +98,6 @@ MapStoreMapConfigProvider.prototype.getAffectedTables = function(callback) { const { dbname } = this.params; const token = mapConfig.id(); - if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { - const affectedTables = this.affectedTablesCache.get(dbname, token); - - return callback(null, affectedTables); - } - const queries = []; mapConfig.getLayers().forEach(layer => { @@ -138,3 +132,21 @@ MapStoreMapConfigProvider.prototype.getAffectedTables = function(callback) { }); }); }; + +MapStoreMapConfigProvider.prototype.getAffectedTables = function (callback) { + this.getMapConfig((err, mapConfig) => { + if (err) { + return callback(err); + } + + const { dbname } = this.params; + const token = mapConfig.id(); + + if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { + const affectedTables = this.affectedTablesCache.get(dbname, token); + return callback(null, affectedTables); + } + + return this.createAffectedTables(callback); + }); +}; diff --git a/lib/cartodb/models/mapconfig/provider/named-map-provider.js b/lib/cartodb/models/mapconfig/provider/named-map-provider.js index 50612065..065d20f4 100644 --- a/lib/cartodb/models/mapconfig/provider/named-map-provider.js +++ b/lib/cartodb/models/mapconfig/provider/named-map-provider.js @@ -262,7 +262,7 @@ NamedMapMapConfigProvider.prototype.getTemplateName = function() { return this.templateName; }; -NamedMapMapConfigProvider.prototype.getAffectedTables = function(callback) { +NamedMapMapConfigProvider.prototype.createAffectedTables = function(callback) { this.getMapConfig((err, mapConfig) => { if (err) { return callback(err); @@ -271,11 +271,6 @@ NamedMapMapConfigProvider.prototype.getAffectedTables = function(callback) { const { dbname } = this.rendererParams; const token = mapConfig.id(); - if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { - const affectedTables = this.affectedTablesCache.get(dbname, token); - return callback(null, affectedTables); - } - const queries = []; mapConfig.getLayers().forEach(layer => { @@ -310,3 +305,21 @@ NamedMapMapConfigProvider.prototype.getAffectedTables = function(callback) { }); }); }; + +NamedMapMapConfigProvider.prototype.getAffectedTables = function (callback) { + this.getMapConfig((err, mapConfig) => { + if (err) { + return callback(err); + } + + const { dbname } = this.params; + const token = mapConfig.id(); + + if (this.affectedTablesCache.hasAffectedTables(dbname, token)) { + const affectedTables = this.affectedTablesCache.get(dbname, token); + return callback(null, affectedTables); + } + + return this.createAffectedTables(callback); + }); +};