From 1d433bf5b22ca86d8f4b01c49ee1d8b3983c3859 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 23 Mar 2015 18:58:57 +0100 Subject: [PATCH] Remove table param from generateCacheChannel --- lib/cartodb/server_options.js | 37 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index c6afe11e..1c191871 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -121,6 +121,11 @@ module.exports = function(redisPool) { var dbName = req.params.dbname; var cacheKey = [ dbName, req.params.token ].join(':'); + // no token means no tables associated + if (!req.params.token) { + return callback(null, this.buildCacheChannel(dbName, [])); + } + step( function checkCached() { if ( me.channelCache.hasOwnProperty(cacheKey) ) { @@ -137,7 +142,6 @@ module.exports = function(redisPool) { if ( ! app.mapStore ) { throw new Error('missing channel cache for token ' + req.params.token); } - var next = this; var mapStore = app.mapStore; step( function loadFromStore() { @@ -149,22 +153,24 @@ module.exports = function(redisPool) { } assert.ifError(err); - return mapConfig.obj().layers.map(function(lyr) { - return lyr.options.sql; - }).join(';'); + var queries = mapConfig.getLayers() + .map(function(lyr) { + return lyr.options.sql; + }) + .filter(function(sql) { + return !!sql; + }); + + return queries.length ? queries.join(';') : null; }, - function finish(err, sql) { - next(err, sql); - } + this ); }, function findAffectedTables(err, sql) { assert.ifError(err); + if ( ! sql ) { - if ( ! req.params.table ) { - throw new Error("this request doesn't need an X-Cache-Channel generated"); - } - return [req.params.table]; + throw new Error("this request doesn't need an X-Cache-Channel generated"); } queryTablesApi.getAffectedTablesInQuery(cdbRequest.userByReq(req), sql, this); // in addCacheChannel @@ -172,16 +178,13 @@ module.exports = function(redisPool) { function buildCacheChannel(err, tableNames) { assert.ifError(err); - if (req.profiler && ! req.params.table ) { + if (req.profiler) { req.profiler.done('affectedTables'); } var cacheChannel = me.buildCacheChannel(dbName,tableNames); - // store for caching from me.generateCacheChannel - // (not worth when table was specified in params) - if ( ! req.params.table ) { - me.channelCache[cacheKey] = cacheChannel; - } + me.channelCache[cacheKey] = cacheChannel; + return cacheChannel; }, function finish(err, cacheChannel) {