Stop adding X-Cache-Channel header when no tables were identified in SQL query
Fixes #238 and fixes #157
This commit is contained in:
parent
920cb350cc
commit
875eccba62
@ -488,7 +488,7 @@ function handleQuery(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only set an X-Cache-Channel for responses we want Varnish to cache.
|
// 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));
|
res.header('X-Cache-Channel', generateCacheKey(dbopts.dbname, tableCacheItem, authenticated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.length, 2);
|
||||||
assert.equal(out.rows[0].x[0], '8.7');
|
assert.equal(out.rows[0].x[0], '8.7');
|
||||||
assert.equal(out.rows[0].x[1], '4.3');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -84,4 +84,30 @@ describe('X-Cache-Channel header', function() {
|
|||||||
], done));
|
], 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user