fix: sumsub UI and cache invalidation on l-s

This commit is contained in:
Rafael Taranto 2024-08-12 16:51:34 +01:00
parent d8ce011b28
commit 6ab919c38f
3 changed files with 22 additions and 7 deletions

View file

@ -100,7 +100,9 @@ const populateSettings = function (req, res, next) {
return newSettingsLoader.loadLatest()
.then(settings => {
const versionId = settings.version
settingsCache.set(`${operatorId}-latest`, settings)
settingsCache.set(`${operatorId}-v${versionId}`, settings)
if (!!needsSettingsReload[operatorId]) delete needsSettingsReload[operatorId]
req.settings = settings
})

View file

@ -152,10 +152,11 @@ function resetConfig (schemaVersion) {
}
function loadLatest (schemaVersion) {
return Promise.all([loadLatestConfigOrNone(schemaVersion), loadAccounts(schemaVersion)])
.then(([config, accounts]) => ({
config,
accounts
return Promise.all([loadLatestConfigOrNoneReturningVersion(schemaVersion), loadAccounts(schemaVersion)])
.then(([configObj, accounts]) => ({
config: configObj.config,
accounts,
version: configObj.version
}))
}
@ -175,6 +176,18 @@ function loadLatestConfig () {
})
}
function loadLatestConfigOrNoneReturningVersion (schemaVersion) {
const sql = `select data, id
from user_config
where type=$1
and schema_version=$2
order by id desc
limit 1`
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? { config: row.data.config, version: row.id } : {})
}
function loadLatestConfigOrNone (schemaVersion) {
const sql = `select data
from user_config