fix: merge two conditionals

This commit is contained in:
Sérgio Salgado 2022-10-20 18:06:47 +01:00
parent e919a54c87
commit 240203b060

View file

@ -82,12 +82,15 @@ const populateSettings = function (req, res, next) {
const operatorSettings = settingsCache.get(`${operatorId}-latest`)
if (!versionId && !!needsSettingsReload[operatorId]) {
logger.debug('Fetching and caching a new latest config value, as a reload was requested')
if (!versionId && (!!needsSettingsReload[operatorId] || !operatorSettings)) {
!!needsSettingsReload[operatorId]
? logger.debug('Fetching and caching a new latest config value, as a reload was requested')
: logger.debug('Fetching the latest config version because there\'s no cached value')
return newSettingsLoader.loadLatest()
.then(settings => {
settingsCache.set(`${operatorId}-latest`, settings)
delete needsSettingsReload[operatorId]
if (!!needsSettingsReload[operatorId]) delete needsSettingsReload[operatorId]
req.settings = settings
})
.then(() => next())
@ -99,17 +102,6 @@ const populateSettings = function (req, res, next) {
req.settings = operatorSettings
return next()
}
if (!versionId && !operatorSettings) {
logger.debug('Fetching the latest config version because there\'s no cached value')
return newSettingsLoader.loadLatest()
.then(settings => {
settingsCache.set(`${operatorId}-latest`, settings)
req.settings = settings
})
.then(() => next())
.catch(next)
}
} catch (e) {
logger.error(e)
}