From a894194b6bd455cdc7e65541933c523194ea8ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 4 Jul 2019 15:58:39 +0200 Subject: [PATCH] Add more specific tests --- .../api/middlewares/cache-control-header.js | 6 +++- test/acceptance/cache/cache-control-header.js | 35 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/cartodb/api/middlewares/cache-control-header.js b/lib/cartodb/api/middlewares/cache-control-header.js index 7171c44a..1ef3f2df 100644 --- a/lib/cartodb/api/middlewares/cache-control-header.js +++ b/lib/cartodb/api/middlewares/cache-control-header.js @@ -24,7 +24,7 @@ module.exports = function setCacheControlHeader ({ const directives = [ 'public' ]; - if (affectedTables && !affectedTables.getTables().some(table => !!table.updated_at)) { + if (everyAffectedTablesCanBeInvalidated(affectedTables)) { directives.push(`max-age=${fallbackTtl}`); } else { directives.push(`max-age=${ttl}`); @@ -40,3 +40,7 @@ module.exports = function setCacheControlHeader ({ }); }; }; + +function everyAffectedTablesCanBeInvalidated (affectedTables) { + return affectedTables && affectedTables.getTables().some(table => !table.updated_at); +} diff --git a/test/acceptance/cache/cache-control-header.js b/test/acceptance/cache/cache-control-header.js index f318214d..40bc0355 100644 --- a/test/acceptance/cache/cache-control-header.js +++ b/test/acceptance/cache/cache-control-header.js @@ -72,8 +72,41 @@ describe('cache-control header', function () { }); }); - it('tile from a dynamic query which doesn\'t use a table' , function (done) { + it('tile from joined tables which one of them is NOT included in cdb_tablemetada', function (done) { const ttl = global.environment.varnish.fallbackTtl || FIVE_MINUTES_IN_SECONDS; + const mapConfig = createMapConfig([{ + type: 'cartodb', + options: { + sql: ` + select + t.cartodb_id, + t.the_geom, + t.the_geom_webmercator + from + test_table t, + test_table_2 t2 + where + t.cartodb_id = t2.cartodb_id + `, + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + }]); + + const testClient = new TestClient(mapConfig); + + testClient.getTile(0, 0, 0, {}, function (err, res) { + if (err) { + return done(err); + } + + assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`); + testClient.drain(done); + }); + }); + + it('tile from a dynamic query which doesn\'t use a table' , function (done) { + const ttl = ONE_YEAR_IN_SECONDS; const mapConfig = createMapConfig(); const testClient = new TestClient(mapConfig);