From 39625e044b6d1a20e7485b6f9fc6c0b1f6408dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 8 Jul 2019 11:48:32 +0200 Subject: [PATCH 1/2] Set defaults to avoid error when confing is not provided --- app/controllers/query_controller.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/query_controller.js b/app/controllers/query_controller.js index f570542e..0fd9db4c 100644 --- a/app/controllers/query_controller.js +++ b/app/controllers/query_controller.js @@ -25,6 +25,10 @@ const logMiddleware = require('../middlewares/log'); const ONE_YEAR_IN_SECONDS = 31536000; // ttl in cache provider const FIVE_MINUTES_IN_SECONDS = 60 * 5; // ttl in cache provider +const cacheControl = Object.assign({ + ttl: ONE_YEAR_IN_SECONDS, + fallbackTtl: FIVE_MINUTES_IN_SECONDS +}, global.settings.cache) function QueryController(metadataBackend, userDatabaseService, tableCache, statsd_client, userLimitsService) { this.metadataBackend = metadataBackend; @@ -192,10 +196,10 @@ QueryController.prototype.handleQuery = function (req, res, next) { res.header('Cache-Control', 'public,max-age=' + ONE_YEAR_IN_SECONDS); } else { if (affectedTables && affectedTables.getTables().every(table => table.updated_at !== null)) { - const maxAge = mayWrite ? 0 : (global.settings.cache.ttl || ONE_YEAR_IN_SECONDS); + const maxAge = mayWrite ? 0 : cacheControl.ttl; res.header('Cache-Control', `no-cache,max-age=${maxAge},must-revalidate,public`); } else { - const maxAge = global.settings.cache.fallbackTtl || FIVE_MINUTES_IN_SECONDS; + const maxAge = cacheControl.fallbackTtl; res.header('Cache-Control', `no-cache,max-age=${maxAge},must-revalidate,public`); } } From 077b6def124993b9c32fee8f5fa9a1466a770aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 8 Jul 2019 11:57:36 +0200 Subject: [PATCH 2/2] Please linter --- app/controllers/query_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/query_controller.js b/app/controllers/query_controller.js index 0fd9db4c..aba4e439 100644 --- a/app/controllers/query_controller.js +++ b/app/controllers/query_controller.js @@ -28,7 +28,7 @@ const FIVE_MINUTES_IN_SECONDS = 60 * 5; // ttl in cache provider const cacheControl = Object.assign({ ttl: ONE_YEAR_IN_SECONDS, fallbackTtl: FIVE_MINUTES_IN_SECONDS -}, global.settings.cache) +}, global.settings.cache); function QueryController(metadataBackend, userDatabaseService, tableCache, statsd_client, userLimitsService) { this.metadataBackend = metadataBackend;