From d4b1f580ff885feac5583e74e9b8054ad2954fdd Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 18 Feb 2013 16:14:15 +0100 Subject: [PATCH] Fix X-Cache-Channel computation with paging parameters. Closes #85. --- NEWS.md | 1 + app/controllers/app.js | 2 +- app/models/psql.js | 4 ++-- test/acceptance/app.test.js | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 09fab9bf..e6a88312 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * Add pid to /cachestatus (#83) * Check CDB_QueryTable response before saving into cache (#83) * Use an expiring LRU cache for query tables (#83) +* Fix X-Cache-Channel computation with paging parameters (#85) 1.3.4 (21/01/13) ----- diff --git a/app/controllers/app.js b/app/controllers/app.js index dd10d0f4..9c07f078 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -183,7 +183,7 @@ function handleQuery(req, res) { tableCacheItem.hits++; return false; } else { - pg.query("SELECT CDB_QueryTables($quotesql$" + sql + "$quotesql$)", this); + pg.query("SELECT CDB_QueryTables($quotesql$" + sql + "$quotesql$)", this, true); } }, function queryResult(err, result){ diff --git a/app/models/psql.js b/app/models/psql.js index 5bb12bf9..b0874742 100644 --- a/app/models/psql.js +++ b/app/models/psql.js @@ -54,7 +54,7 @@ var PSQL = function(user_id, db, limit, offset){ } }; - me.query = function(sql, callback){ + me.query = function(sql, callback, skip_window){ var that = this; Step( @@ -67,7 +67,7 @@ var PSQL = function(user_id, db, limit, offset){ }, function(err, client){ if (err) return callback(err, null); - client.query(that.window_sql(sql), this); + client.query(skip_window ? sql : that.window_sql(sql), this); }, function(err, res){ //if (err) console.log(err); diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index ba3b2fc2..90359e73 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -111,6 +111,25 @@ function(done){ }); }); +// Test for https://github.com/Vizzuality/CartoDB-SQL-API/issues/85 +test("paging doesn't break x-cache-channel", +function(done){ + assert.response(app, { + url: '/api/v1/sql?' + querystring.stringify({ + q: 'SELECT cartodb_id*3 FROM untitle_table_4', + api_key: '1234', + rows_per_page: 1, + page: 2 + }), + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res) { + assert.equal(res.statusCode, 200, res.body); + assert.equal(res.headers['x-cache-channel'], 'cartodb_test_user_1_db:untitle_table_4'); + done(); + }); +}); + test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){ assert.response(app, {