A non empty datasource from MapConfigNamedLayersAdapter.getLayers
means the affected tables can have private tables involved. That implies QueryTablesApi will need the proper user to use CDB_QueryTables. So we store it in a request context to use it in the afterLayergroupCreate call. Tiles for these layergroups will fail to add a X-Cache-Channel header because it won't be possible to use the proper user within those tiles. Ok, they will fail if they are not requested through the same tiler instance because if they are they most likely will reuse the in memory cache. See https://github.com/CartoDB/Windshaft-cartodb/issues/253
This commit is contained in:
parent
fbecc11aa5
commit
c17af23a40
@ -312,6 +312,12 @@ module.exports = function(redisPool) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!datasource.isEmpty()) {
|
||||
setContext(req, 'queryTablesApiDatasource', _.find(datasource.layersDbParams, function(layerDbParams) {
|
||||
return !!layerDbParams;
|
||||
}));
|
||||
}
|
||||
|
||||
requestMapConfig.layers = layers;
|
||||
return callback(null, requestMapConfig, datasource)
|
||||
});
|
||||
@ -366,14 +372,16 @@ module.exports = function(redisPool) {
|
||||
|
||||
Step(
|
||||
function getAffectedTablesAndLastUpdatedTime() {
|
||||
queryTablesApi.getAffectedTablesAndLastUpdatedTime(usr, {
|
||||
var queryTablesOpts = {
|
||||
user: req.params.dbuser,
|
||||
pass: req.params.dbpass,
|
||||
host: req.params.dbhost,
|
||||
port: req.params.dbport,
|
||||
dbname: req.params.dbname,
|
||||
api_key: key
|
||||
}, sql, this);
|
||||
};
|
||||
_.extend(queryTablesOpts, getContext(req, 'queryTablesApiDatasource'));
|
||||
queryTablesApi.getAffectedTablesAndLastUpdatedTime(usr, queryTablesOpts, sql, this);
|
||||
},
|
||||
function handleAffectedTablesAndLastUpdatedTime(err, result) {
|
||||
if (req.profiler) req.profiler.done('queryTablesAndLastUpdated');
|
||||
@ -873,5 +881,36 @@ module.exports = function(redisPool) {
|
||||
);
|
||||
};
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* Private methods
|
||||
******************************************************************************************************************/
|
||||
|
||||
/**
|
||||
* Handles context for a given Request object
|
||||
* @param {Object|IncomingMessage} req
|
||||
* @param {String} key
|
||||
* @returns {*}
|
||||
*/
|
||||
function getContext(req, key) {
|
||||
return req.context && req.context[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles context for a given Request object
|
||||
* @param {Object|IncomingMessage} req
|
||||
* @param {String} key
|
||||
* @param {*} value
|
||||
* @returns {*} The previous value
|
||||
*/
|
||||
function setContext(req, key, value) {
|
||||
var previousValue;
|
||||
if (value) {
|
||||
req.context = req.context || {};
|
||||
previousValue = req.context[key];
|
||||
req.context[key] = value;
|
||||
}
|
||||
return previousValue;
|
||||
}
|
||||
|
||||
return me;
|
||||
};
|
||||
|
@ -422,10 +422,17 @@ suite('named_layers', function() {
|
||||
}
|
||||
},
|
||||
function(res, err) {
|
||||
next(err);
|
||||
next(err, res);
|
||||
}
|
||||
);
|
||||
},
|
||||
function handleTileResponse(err, res) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
//assert.ok(res.headers['X-Cache-Channel']); -> https://github.com/CartoDB/Windshaft-cartodb/issues/253
|
||||
return true;
|
||||
},
|
||||
function deleteTemplate(err) {
|
||||
var next = this;
|
||||
templateMaps.delTemplate(username, privateTableTemplate, function(/*delErr*/) {
|
||||
|
Loading…
Reference in New Issue
Block a user