Feat: implement per operator settings cache
Fix: fix linter-found issues Chore: move findOperatorId to own middleware file Chore: delete old routes.js file and rename new-routes.js to routes.js Fix: PR fixes
This commit is contained in:
parent
85235eaa13
commit
558317e9f3
30 changed files with 232 additions and 860 deletions
|
|
@ -6,26 +6,27 @@ const helpers = require('../route-helpers')
|
|||
const SETTINGS_CACHE_REFRESH = 60 * 60 * 1000
|
||||
|
||||
const populateSettings = function (req, res, next) {
|
||||
const operatorId = res.locals.operatorId
|
||||
const versionId = req.headers['config-version']
|
||||
if (versionId !== state.oldVersionId) {
|
||||
state.oldVersionId = versionId
|
||||
}
|
||||
|
||||
// Clear cache every hour
|
||||
if (Date.now() - settingsCache.getTimestamp() > SETTINGS_CACHE_REFRESH) {
|
||||
settingsCache.clearCache()
|
||||
if (Date.now() - settingsCache.getTimestamp(operatorId) > SETTINGS_CACHE_REFRESH) {
|
||||
settingsCache.clear(operatorId)
|
||||
}
|
||||
|
||||
if (!versionId && settingsCache.getCache()) {
|
||||
req.settings = settingsCache.getCache()
|
||||
if (!versionId && settingsCache.getCache(operatorId)) {
|
||||
req.settings = settingsCache.getCache(operatorId)
|
||||
return next()
|
||||
}
|
||||
|
||||
if (!versionId && !settingsCache.getCache()) {
|
||||
if (!versionId && !settingsCache.getCache(operatorId)) {
|
||||
return newSettingsLoader.loadLatest()
|
||||
.then(settings => {
|
||||
settingsCache.setCache(settings)
|
||||
settingsCache.setTimestamp(Date.now())
|
||||
settingsCache.setCache(operatorId, settings)
|
||||
settingsCache.setTimestamp(operatorId, Date.now())
|
||||
req.settings = settings
|
||||
})
|
||||
.then(() => next())
|
||||
|
|
@ -39,4 +40,4 @@ const populateSettings = function (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
module.exports = populateSettings
|
||||
module.exports = populateSettings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue