Skip query tables cache for authenticated requests
This commit is contained in:
parent
b453f2b2d0
commit
66cd1f400f
@ -136,8 +136,9 @@ QueryController.prototype.handleQuery = function (req, res) {
|
||||
checkAborted('queryExplain');
|
||||
|
||||
var pg = new PSQL(authDbParams, {}, { destroyOnError: true });
|
||||
var skipCache = !!dbopts.authenticated;
|
||||
|
||||
self.queryTables.getAffectedTablesFromQuery(pg, sql, function(err, result) {
|
||||
self.queryTables.getAffectedTablesFromQuery(pg, sql, skipCache, function(err, result) {
|
||||
if (err) {
|
||||
var errorMessage = (err && err.message) || 'unknown error';
|
||||
console.error("Error on query explain '%s': %s", sql, errorMessage);
|
||||
|
@ -8,11 +8,15 @@ function CachedQueryTables(tableCache) {
|
||||
|
||||
module.exports = CachedQueryTables;
|
||||
|
||||
CachedQueryTables.prototype.getAffectedTablesFromQuery = function(pg, sql, callback) {
|
||||
CachedQueryTables.prototype.getAffectedTablesFromQuery = function(pg, sql, skipCache, callback) {
|
||||
var self = this;
|
||||
|
||||
var cacheKey = sqlCacheKey(pg.username(), sql);
|
||||
var cachedResult = this.tableCache.get(cacheKey);
|
||||
|
||||
var cachedResult;
|
||||
if (!skipCache) {
|
||||
cachedResult = this.tableCache.get(cacheKey);
|
||||
}
|
||||
|
||||
if (cachedResult) {
|
||||
cachedResult.hits++;
|
||||
|
@ -64,4 +64,28 @@ describe('query-tables-api', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip cache to retrieve affected tables', function(done) {
|
||||
var authenticatedRequest = {
|
||||
url: '/api/v1/sql?' + qs.stringify({
|
||||
q: 'SELECT * FROM untitle_table_4',
|
||||
api_key: '1234'
|
||||
}),
|
||||
headers: {
|
||||
host: 'vizzuality.cartodb.com'
|
||||
},
|
||||
method: 'GET'
|
||||
};
|
||||
assert.response(app, authenticatedRequest, RESPONSE_OK, function(res, err) {
|
||||
assert.ok(!err, err);
|
||||
|
||||
getCacheStatus(function(err, cacheStatus) {
|
||||
assert.ok(!err, err);
|
||||
assert.equal(cacheStatus.explain.keys, 1);
|
||||
assert.equal(cacheStatus.explain.hits, 0);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user