From 329b5d9b9e6a9d8cf4658f2bab0216402d5770a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 13 Sep 2019 18:07:50 +0200 Subject: [PATCH] Use ES6 class syntax --- lib/cartodb/cache/named_map_provider_cache.js | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/cartodb/cache/named_map_provider_cache.js b/lib/cartodb/cache/named_map_provider_cache.js index fbb01509..5883ce07 100644 --- a/lib/cartodb/cache/named_map_provider_cache.js +++ b/lib/cartodb/cache/named_map_provider_cache.js @@ -8,58 +8,58 @@ const { templateName } = require('../backends/template_maps'); const TEN_MINUTES_IN_MILLISECONDS = 1000 * 60 * 10; const ACTIONS = ['update', 'delete']; -function NamedMapProviderCache( - templateMaps, - pgConnection, - metadataBackend, - userLimitsBackend, - mapConfigAdapter, - affectedTablesCache -) { - this.templateMaps = templateMaps; - this.pgConnection = pgConnection; - this.metadataBackend = metadataBackend; - this.userLimitsBackend = userLimitsBackend; - this.mapConfigAdapter = mapConfigAdapter; - this.affectedTablesCache = affectedTablesCache; +module.exports = class NamedMapProviderCache { + constructor ( + templateMaps, + pgConnection, + metadataBackend, + userLimitsBackend, + mapConfigAdapter, + affectedTablesCache + ) { + this.templateMaps = templateMaps; + this.pgConnection = pgConnection; + this.metadataBackend = metadataBackend; + this.userLimitsBackend = userLimitsBackend; + this.mapConfigAdapter = mapConfigAdapter; + this.affectedTablesCache = affectedTablesCache; - this.providerCache = new LruCache({ max: 2000, maxAge: TEN_MINUTES_IN_MILLISECONDS }); + this.providerCache = new LruCache({ max: 2000, maxAge: TEN_MINUTES_IN_MILLISECONDS }); - ACTIONS.forEach(action => templateMaps.on(action, (...args) => this.invalidate(...args))); -} + ACTIONS.forEach(action => templateMaps.on(action, (...args) => this.invalidate(...args))); + } -module.exports = NamedMapProviderCache; + get (user, templateId, config, authToken, params, callback) { + const namedMapKey = createNamedMapKey(user, templateId); + const namedMapProviders = this.providerCache.get(namedMapKey) || {}; + const providerKey = createProviderKey(config, authToken, params); -NamedMapProviderCache.prototype.get = function(user, templateId, config, authToken, params, callback) { - const namedMapKey = createNamedMapKey(user, templateId); - const namedMapProviders = this.providerCache.get(namedMapKey) || {}; - const providerKey = createProviderKey(config, authToken, params); + if (namedMapProviders.hasOwnProperty(providerKey)) { + return callback(null, namedMapProviders[providerKey]); + } + + namedMapProviders[providerKey] = new NamedMapMapConfigProvider( + this.templateMaps, + this.pgConnection, + this.metadataBackend, + this.userLimitsBackend, + this.mapConfigAdapter, + this.affectedTablesCache, + user, + templateId, + config, + authToken, + params + ); + + this.providerCache.set(namedMapKey, namedMapProviders); - if (namedMapProviders.hasOwnProperty(providerKey)) { return callback(null, namedMapProviders[providerKey]); } - namedMapProviders[providerKey] = new NamedMapMapConfigProvider( - this.templateMaps, - this.pgConnection, - this.metadataBackend, - this.userLimitsBackend, - this.mapConfigAdapter, - this.affectedTablesCache, - user, - templateId, - config, - authToken, - params - ); - - this.providerCache.set(namedMapKey, namedMapProviders); - - return callback(null, namedMapProviders[providerKey]); -}; - -NamedMapProviderCache.prototype.invalidate = function(user, templateId) { - this.providerCache.del(createNamedMapKey(user, templateId)); + invalidate (user, templateId) { + this.providerCache.del(createNamedMapKey(user, templateId)); + } }; function createNamedMapKey (user, templateId) {