Skip to content

Commit

Permalink
Stop adding X-Cache-Channel header when no tables were identified in …
Browse files Browse the repository at this point in the history
…SQL query

Fixes #238 and fixes #157
  • Loading branch information
rochoa committed Sep 7, 2015
1 parent 920cb35 commit 875eccb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function handleQuery(req, res) {
}

// Only set an X-Cache-Channel for responses we want Varnish to cache.
if ( tableCacheItem && ! tableCacheItem.may_write ) {
if ( tableCacheItem && tableCacheItem.affected_tables.length > 0 && !tableCacheItem.may_write ) {
res.header('X-Cache-Channel', generateCacheKey(dbopts.dbname, tableCacheItem, authenticated));
}

Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ it('numeric arrays are rendered as such', function(done){
assert.equal(out.rows[0].x.length, 2);
assert.equal(out.rows[0].x[0], '8.7');
assert.equal(out.rows[0].x[1], '4.3');
assert.equal(res.headers['x-cache-channel'], 'cartodb_test_user_1_db:'); // keep forever
assert.equal(res.headers.hasOwnProperty('x-cache-channel'), false);
done();
});
});
Expand Down
26 changes: 26 additions & 0 deletions test/acceptance/x-cache-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,30 @@ describe('X-Cache-Channel header', function() {
], done));
});

it('should not add header for functions', function(done) {
var sql = "SELECT format('%s', 'wadus')";
assert.response(app, createGetRequest(sql), RESPONSE_OK, function(res) {
assert.ok(!res.headers.hasOwnProperty('x-cache-channel'), res.headers['x-cache-channel']);
done();
});
});

it('should not add header for CDB_QueryTables', function(done) {
var sql = "SELECT CDB_QueryTablesText('select * from untitle_table_4')";
assert.response(app, createGetRequest(sql), RESPONSE_OK, function(res) {
assert.ok(!res.headers.hasOwnProperty('x-cache-channel'), res.headers['x-cache-channel']);
done();
});
});

it('should not add header for non table results', function(done) {
var sql = "SELECT 'wadus'::text";
assert.response(app, createGetRequest(sql), RESPONSE_OK, function(res) {
assert.ok(!res.headers.hasOwnProperty('x-cache-channel'), res.headers['x-cache-channel']);
done();
});
});



});

0 comments on commit 875eccb

Please sign in to comment.