Use early return pattern

This commit is contained in:
Daniel García Aubert 2019-09-13 16:53:53 +02:00
parent 6229455d25
commit 3d2f554be9

View File

@ -32,31 +32,29 @@ module.exports = NamedMapProviderCache;
NamedMapProviderCache.prototype.get = function(user, templateId, config, authToken, params, callback) {
var namedMapKey = createNamedMapKey(user, templateId);
var namedMapProviders = this.providerCache.get(namedMapKey) || {};
var providerKey = createProviderKey(config, authToken, params);
if (!namedMapProviders.hasOwnProperty(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);
// early exit, if provider did not exist we just return it
if (namedMapProviders.hasOwnProperty(providerKey)) {
return callback(null, namedMapProviders[providerKey]);
}
var namedMapProvider = namedMapProviders[providerKey];
namedMapProviders[providerKey] = new NamedMapMapConfigProvider(
this.templateMaps,
this.pgConnection,
this.metadataBackend,
this.userLimitsBackend,
this.mapConfigAdapter,
this.affectedTablesCache,
user,
templateId,
config,
authToken,
params
);
return callback(null, namedMapProvider);
this.providerCache.set(namedMapKey, namedMapProviders);
return callback(null, namedMapProviders[providerKey]);
};
NamedMapProviderCache.prototype.invalidate = function(user, templateId) {