diff --git a/lib/cartodb/api/middlewares/cache-control-header.js b/lib/cartodb/api/middlewares/cache-control-header.js index c3c57ea0..d15b259c 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 (everyAffectedTablesCanBeInvalidated(affectedTables)) { + if (everyAffectedTableCanBeInvalidated(affectedTables)) { directives.push(`max-age=${ttl}`); } else { directives.push(`max-age=${fallbackTtl}`); @@ -41,6 +41,11 @@ module.exports = function setCacheControlHeader ({ }; }; -function everyAffectedTablesCanBeInvalidated (affectedTables) { - return affectedTables && affectedTables.getTables().every(table => table.updated_at !== null); +function everyAffectedTableCanBeInvalidated (affectedTables) { + const skipNotUpdatedAtTables = false; + const skipAnalysisCachedTables = true; + + return affectedTables && + affectedTables.getTables(skipNotUpdatedAtTables, skipAnalysisCachedTables) + .every(table => table.updated_at !== null); } diff --git a/package-lock.json b/package-lock.json index 1339f77c..2b38e3d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "resolved": "https://registry.npmjs.org/@carto/mapnik/-/mapnik-3.6.2-carto.15.tgz", "integrity": "sha512-O6YpFQ8NRJJZjiQJxoS92Hpjci1tvd4SWKxaicG3SuRBqVGY3BKdhChL+6Ck6tRZvW3O577987vVwEnYKALTCA==", "requires": { - "mapnik-vector-tile": "github:cartodb/mapnik-vector-tile#e7ca5471f9e5de81243e6035e70444321fc0a82f", + "mapnik-vector-tile": "github:cartodb/mapnik-vector-tile#v1.6.1-carto.2", "nan": "2.14.0", "node-pre-gyp": "0.13.0" }, @@ -389,7 +389,7 @@ }, "carto": { "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", - "from": "github:cartodb/carto#0.15.1-cdb5", + "from": "github:cartodb/carto#master", "requires": { "mapnik-reference": "~6.0.2", "optimist": "~0.6.0", @@ -417,14 +417,14 @@ "integrity": "sha512-1z3Dk9G8KQlNGurbcmGBvNj8DVCh1Keue9uzyyvB6hKOYzBHMxixAMG0D+8nSsA7oQmWUsx/xkZZ5ZxT9toEHA==", "requires": { "debug": "^3.1.0", - "pg": "github:cartodb/node-postgres#5417d7b29b7272ca2e71bb396899ab3f177a9ae6", + "pg": "github:cartodb/node-postgres#6.4.2-cdb2", "underscore": "~1.6.0" } }, "cartodb-query-tables": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/cartodb-query-tables/-/cartodb-query-tables-0.4.0.tgz", - "integrity": "sha512-abhhz2juO1IO9hZvv10WAtgt77UTk2Fc/6BK7pml+0Cnd0HMfDC+XKzfY+r/wEjyEa20IXTc//cPsP0BgevyMw==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cartodb-query-tables/-/cartodb-query-tables-0.5.0.tgz", + "integrity": "sha512-xVHWKF6DMSn/Ksqhm6uNNnr8ckWDWWzsTz9XsoELAW5ZpCJDaxn3YGxgRtD1bwHdQd1tjDVeud/pRk/mCFWpmQ==" }, "cartodb-redis": { "version": "2.1.0", @@ -2044,7 +2044,7 @@ "carto": "0.16.3", "debug": "~3.1.0", "generic-pool": "~2.2.0", - "millstone": "github:cartodb/millstone#f201885250d2d7ea6c870a1e1060ca6bcfdef186", + "millstone": "github:cartodb/millstone#v0.6.17-carto.2", "postcss": "~5.2.8", "postcss-scss": "0.4.0", "postcss-strip-inline-comments": "0.1.5", @@ -3925,26 +3925,10 @@ "resolved": "https://registry.npmjs.org/torque.js/-/torque.js-3.1.1.tgz", "integrity": "sha512-kfIrmI7TGqJT/J9DH8Mgvd9VEwcvAtnvyYyqymSN6WZ5L4BaVQEQ+zu5FgLChNAqCaRkqGc7bKp0Hj9A0rempA==", "requires": { - "carto": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", + "carto": "github:cartodb/carto#master", "d3": "3.5.17", "turbo-carto": "^0.21.1", "turf-jenks": "~1.0.1" - }, - "dependencies": { - "carto": { - "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", - "from": "github:cartodb/carto#master", - "requires": { - "mapnik-reference": "~6.0.2", - "optimist": "~0.6.0", - "underscore": "1.8.3" - } - }, - "underscore": { - "version": "1.8.3", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", - "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" - } } }, "tough-cookie": { @@ -4116,7 +4100,7 @@ "@carto/cartonik": "^0.6.0", "@carto/mapnik": "3.6.2-carto.15", "canvas": "^2.4.1", - "carto": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", + "carto": "github:cartodb/carto#0.15.1-cdb5", "cartodb-psql": "0.13.1", "debug": "3.1.0", "grainstore": "^2.0.0", @@ -4126,6 +4110,24 @@ "semver": "5.5.0", "torque.js": "3.1.1", "underscore": "1.6.0" + }, + "dependencies": { + "carto": { + "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", + "from": "github:cartodb/carto#0.15.1-cdb5", + "requires": { + "mapnik-reference": "~6.0.2", + "optimist": "~0.6.0", + "underscore": "1.8.3" + }, + "dependencies": { + "underscore": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", + "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" + } + } + } } }, "wordwrap": { diff --git a/package.json b/package.json index 374b1923..f6582f01 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "body-parser": "1.18.3", "camshaft": "^0.64.0", "cartodb-psql": "0.13.1", - "cartodb-query-tables": "0.4.0", + "cartodb-query-tables": "^0.5.0", "cartodb-redis": "2.1.0", "debug": "3.1.0", "dot": "1.1.2", diff --git a/test/acceptance/cache/cache-control-header.js b/test/acceptance/cache/cache-control-header.js index 6bd4e9e3..5a738700 100644 --- a/test/acceptance/cache/cache-control-header.js +++ b/test/acceptance/cache/cache-control-header.js @@ -16,11 +16,19 @@ const defaultLayers = [{ cartocss_version: '2.3.0' } }]; +const defaultDatavies = {}; +const defaultAnalyses = []; -function createMapConfig (layers = defaultLayers) { +function createMapConfig ({ + layers = defaultLayers, + dataviews = defaultDatavies, + analyses = defaultAnalyses +} = {}) { return { version: '1.8.0', - layers: layers + layers: layers, + dataviews: dataviews || {}, + analyses: analyses || [] }; } @@ -28,14 +36,16 @@ describe('cache-control header', function () { describe('max-age directive', function () { it('tile from a table which is included in cdb_tablemetada', function (done) { const ttl = ONE_YEAR_IN_SECONDS; - const mapConfig = createMapConfig([{ - type: 'cartodb', - options: { - sql: 'select * from test_table', - cartocss: TestClient.CARTOCSS.POINTS, - cartocss_version: '2.3.0' - } - }]); + const mapConfig = createMapConfig({ + layers: [{ + type: 'cartodb', + options: { + sql: 'select * from test_table', + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + }] + }); const testClient = new TestClient(mapConfig); @@ -51,14 +61,16 @@ describe('cache-control header', function () { it('tile from a table which 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 * from test_table_2', - cartocss: TestClient.CARTOCSS.POINTS, - cartocss_version: '2.3.0' - } - }]); + const mapConfig = createMapConfig({ + layers: [{ + type: 'cartodb', + options: { + sql: 'select * from test_table_2', + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + }] + }); const testClient = new TestClient(mapConfig); @@ -74,24 +86,26 @@ describe('cache-control header', function () { 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 mapConfig = createMapConfig({ + layers: [{ + 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); @@ -120,5 +134,46 @@ describe('cache-control header', function () { testClient.drain(done); }); }); + + it('tile from a cached analysis table which is not included in cdb_tablemetada', function (done) { + const ttl = ONE_YEAR_IN_SECONDS; + const mapConfig = createMapConfig({ + layers: [{ + type: 'cartodb', + options: { + source: { + id: 'HEAD' + }, + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + }], + analyses: [{ + id: 'HEAD', + type: 'buffer', + params: { + source: { + id: 'source_1', + type: 'source', + params: { + query: 'select * from test_table' + } + }, + radius: 60000 + } + }] + }); + + const testClient = new TestClient(mapConfig, 1234); + + 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); + }); + }); }); });