No sql param in generateCacheChannel
This commit is contained in:
parent
415d0c42d5
commit
ea3d2124dc
@ -2,7 +2,6 @@ var _ = require('underscore');
|
|||||||
var step = require('step');
|
var step = require('step');
|
||||||
var QueryTablesApi = require('./api/query_tables_api');
|
var QueryTablesApi = require('./api/query_tables_api');
|
||||||
var PgConnection = require('./backends/pg_connection');
|
var PgConnection = require('./backends/pg_connection');
|
||||||
var crypto = require('crypto');
|
|
||||||
var LZMA = require('lzma').LZMA;
|
var LZMA = require('lzma').LZMA;
|
||||||
var TemplateMaps = require('./template_maps.js');
|
var TemplateMaps = require('./template_maps.js');
|
||||||
var MapConfigNamedLayersAdapter = require('./models/mapconfig_named_layers_adapter');
|
var MapConfigNamedLayersAdapter = require('./models/mapconfig_named_layers_adapter');
|
||||||
@ -120,35 +119,21 @@ module.exports = function(redisPool) {
|
|||||||
return dbName + ':' + tableNames.join(',');
|
return dbName + ':' + tableNames.join(',');
|
||||||
};
|
};
|
||||||
|
|
||||||
me.generateMD5 = function(data){
|
|
||||||
var hash = crypto.createHash('md5');
|
|
||||||
hash.update(data);
|
|
||||||
return hash.digest('hex');
|
|
||||||
};
|
|
||||||
|
|
||||||
me.generateCacheChannel = function(app, req, callback){
|
me.generateCacheChannel = function(app, req, callback){
|
||||||
|
|
||||||
// Build channelCache key
|
// Build channelCache key
|
||||||
var dbName = req.params.dbname;
|
var dbName = req.params.dbname;
|
||||||
var cacheKey = [ dbName ];
|
var cacheKey = [ dbName, req.params.token ].join(':');
|
||||||
if ( req.params.token ) cacheKey.push(req.params.token);
|
|
||||||
else if ( req.params.sql ) cacheKey.push( me.generateMD5(req.params.sql) );
|
|
||||||
cacheKey = cacheKey.join(':');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
step(
|
step(
|
||||||
function checkCached() {
|
function checkCached() {
|
||||||
if ( me.channelCache.hasOwnProperty(cacheKey) ) {
|
if ( me.channelCache.hasOwnProperty(cacheKey) ) {
|
||||||
callback(null, me.channelCache[cacheKey]);
|
return callback(null, me.channelCache[cacheKey]);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
function extractSQL(err) {
|
function extractSQL(err) {
|
||||||
if ( err ) throw err;
|
assert.ifError(err);
|
||||||
|
|
||||||
if ( req.params.token ) {
|
|
||||||
// TODO: cached cache channel for token-based access should
|
// TODO: cached cache channel for token-based access should
|
||||||
// be constructed at renderer cache creation time
|
// be constructed at renderer cache creation time
|
||||||
// See http://github.com/CartoDB/Windshaft-cartodb/issues/152
|
// See http://github.com/CartoDB/Windshaft-cartodb/issues/152
|
||||||
@ -162,36 +147,22 @@ module.exports = function(redisPool) {
|
|||||||
mapStore.load(req.params.token, this);
|
mapStore.load(req.params.token, this);
|
||||||
},
|
},
|
||||||
function getSQL(err, mapConfig) {
|
function getSQL(err, mapConfig) {
|
||||||
if (req.profiler) req.profiler.done('mapStore_load');
|
if (req.profiler) {
|
||||||
if ( err ) throw err;
|
req.profiler.done('mapStore_load');
|
||||||
var sql = [];
|
}
|
||||||
_.each(mapConfig.obj().layers, function(lyr) {
|
assert.ifError(err);
|
||||||
sql.push(lyr.options.sql);
|
|
||||||
});
|
return mapConfig.obj().layers.map(function(lyr) {
|
||||||
sql = sql.join(';');
|
return lyr.options.sql;
|
||||||
return sql;
|
}).join(';');
|
||||||
},
|
},
|
||||||
function finish(err, sql) {
|
function finish(err, sql) {
|
||||||
next(err, sql);
|
next(err, sql);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! req.params.sql ) {
|
|
||||||
return null; // no sql
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have sql, and no token...
|
|
||||||
|
|
||||||
// strip out windshaft/mapnik inserted sql if present
|
|
||||||
var sql = req.params.sql.match(/^\((.*)\)\sas\scdbq$/);
|
|
||||||
sql = (sql !== null) ? sql[1] : req.params.sql;
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
},
|
},
|
||||||
function findAffectedTables(err, sql) {
|
function findAffectedTables(err, sql) {
|
||||||
if ( err ) throw err;
|
assert.ifError(err);
|
||||||
if ( ! sql ) {
|
if ( ! sql ) {
|
||||||
if ( ! req.params.table ) {
|
if ( ! req.params.table ) {
|
||||||
throw new Error("this request doesn't need an X-Cache-Channel generated");
|
throw new Error("this request doesn't need an X-Cache-Channel generated");
|
||||||
@ -202,12 +173,12 @@ module.exports = function(redisPool) {
|
|||||||
queryTablesApi.getAffectedTablesInQuery(cdbRequest.userByReq(req), sql, this); // in addCacheChannel
|
queryTablesApi.getAffectedTablesInQuery(cdbRequest.userByReq(req), sql, this); // in addCacheChannel
|
||||||
},
|
},
|
||||||
function buildCacheChannel(err, tableNames) {
|
function buildCacheChannel(err, tableNames) {
|
||||||
if ( err ) throw err;
|
assert.ifError(err);
|
||||||
|
|
||||||
if (req.profiler && ! req.params.table ) {
|
if (req.profiler && ! req.params.table ) {
|
||||||
req.profiler.done('affectedTables');
|
req.profiler.done('affectedTables');
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbName = req.params.dbname;
|
|
||||||
var cacheChannel = me.buildCacheChannel(dbName,tableNames);
|
var cacheChannel = me.buildCacheChannel(dbName,tableNames);
|
||||||
// store for caching from me.generateCacheChannel
|
// store for caching from me.generateCacheChannel
|
||||||
// (not worth when table was specified in params)
|
// (not worth when table was specified in params)
|
||||||
|
Loading…
Reference in New Issue
Block a user