From a9ab9f8b5cdc0c458b4dbe207a2cdd281ef8a0eb Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 1 Apr 2015 15:11:58 +0200 Subject: [PATCH] Pick render limit and add it to request context - Extends the problematic fake request in templates - Picks the value in waterfall, this must be improved because: 1. It does not make sense if there is no layers with limits 2. If we want to include it always without considering the layer type we can do the operation in parallel --- lib/cartodb/controllers/template_maps.js | 3 +- lib/cartodb/server_options.js | 40 +++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index e071d8a0..df504d82 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -408,7 +408,8 @@ TemplateMapsController.prototype.instantiateTemplate = function(req, res, templa if ( req.profiler ) req.profiler.done('TemplateMaps_instance'); if ( err ) throw err; layergroup = instance; - fakereq = { query: {}, params: {}, headers: _.clone(req.headers), + fakereq = {query: {}, params: {}, headers: _.clone(req.headers), + context: _.clone(req.context), method: req.method, res: res, profiler: req.profiler diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index f3f3e3bd..d8398809 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -1,12 +1,14 @@ var _ = require('underscore'); var step = require('step'); +var LZMA = require('lzma').LZMA; +var assert = require('assert'); +var RedisPool = require('redis-mpool'); + var QueryTablesApi = require('./api/query_tables_api'); var PgConnection = require('./backends/pg_connection'); -var LZMA = require('lzma').LZMA; var TemplateMaps = require('./template_maps.js'); var MapConfigNamedLayersAdapter = require('./models/mapconfig_named_layers_adapter'); var CdbRequest = require('./models/cdb_request'); -var assert = require('assert'); // Whitelist query parameters and attach format var REQUEST_QUERY_PARAMS_WHITELIST = [ @@ -18,8 +20,7 @@ var REQUEST_QUERY_PARAMS_WHITELIST = [ ]; module.exports = function(redisPool) { - redisPool = redisPool || - require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:server_options'})); + redisPool = redisPool || new RedisPool(_.extend(global.environment.redis, {name: 'windshaft:server_options'})); var cartoData = require('cartodb-redis')({ pool: redisPool }), lzmaWorker = new LZMA(), @@ -242,14 +243,37 @@ module.exports = function(redisPool) { }; me.beforeLayergroupCreate = function(req, requestMapConfig, callback) { - mapConfigNamedLayersAdapter.getLayers(cdbRequest.userByReq(req), requestMapConfig.layers, pgConnection, - function(err, layers, datasource) { + var user = cdbRequest.userByReq(req); + var namedLayersDatasource; + step( + function extractNamedLayers() { + mapConfigNamedLayersAdapter.getLayers(user, requestMapConfig.layers, pgConnection, this); + }, + function handleNamedLayers(err, layers, datasource) { + assert.ifError(err); + + namedLayersDatasource = datasource; + requestMapConfig.layers = layers; + + return null; + }, + function getLimits(err) { + assert.ifError(err); + cartoData.getTilerRenderLimit(user, this); + }, + function handleTilerLimits(err, renderLimit) { + assert.ifError(err); + req.context.limits = { + render: renderLimit + }; + return null; + }, + function finish(err) { if (err) { return callback(err); } - requestMapConfig.layers = layers; - return callback(null, requestMapConfig, datasource); + return callback(null, requestMapConfig, namedLayersDatasource); } ); };