Merge pull request #1172 from CartoDB/dgaubert/ch78384/maps-api-replace-log4js-logger-by-pino-bis-bis
Stop using profiler wrongly
This commit is contained in:
commit
0c6d5a1e18
@ -7,7 +7,6 @@ const cleanUpQueryParams = require('../middlewares/clean-up-query-params');
|
|||||||
const credentials = require('../middlewares/credentials');
|
const credentials = require('../middlewares/credentials');
|
||||||
const dbConnSetup = require('../middlewares/db-conn-setup');
|
const dbConnSetup = require('../middlewares/db-conn-setup');
|
||||||
const authorize = require('../middlewares/authorize');
|
const authorize = require('../middlewares/authorize');
|
||||||
const initProfiler = require('../middlewares/init-profiler');
|
|
||||||
const checkJsonContentType = require('../middlewares/check-json-content-type');
|
const checkJsonContentType = require('../middlewares/check-json-content-type');
|
||||||
const incrementMapViewCount = require('../middlewares/increment-map-view-count');
|
const incrementMapViewCount = require('../middlewares/increment-map-view-count');
|
||||||
const augmentLayergroupData = require('../middlewares/augment-layergroup-data');
|
const augmentLayergroupData = require('../middlewares/augment-layergroup-data');
|
||||||
@ -76,7 +75,6 @@ module.exports = class AnonymousMapController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
middlewares () {
|
middlewares () {
|
||||||
const isTemplateInstantiation = false;
|
|
||||||
const useTemplateHash = false;
|
const useTemplateHash = false;
|
||||||
const includeQuery = true;
|
const includeQuery = true;
|
||||||
const label = 'ANONYMOUS LAYERGROUP';
|
const label = 'ANONYMOUS LAYERGROUP';
|
||||||
@ -102,7 +100,6 @@ module.exports = class AnonymousMapController {
|
|||||||
dbConnSetup(this.pgConnection),
|
dbConnSetup(this.pgConnection),
|
||||||
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS),
|
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS),
|
||||||
cleanUpQueryParams(['aggregation']),
|
cleanUpQueryParams(['aggregation']),
|
||||||
initProfiler(isTemplateInstantiation),
|
|
||||||
checkJsonContentType(),
|
checkJsonContentType(),
|
||||||
checkCreateLayergroup(),
|
checkCreateLayergroup(),
|
||||||
prepareAdapterMapConfig(this.mapConfigAdapter),
|
prepareAdapterMapConfig(this.mapConfigAdapter),
|
||||||
@ -143,7 +140,6 @@ function checkCreateLayergroup () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.profiler.done('checkCreateLayergroup');
|
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -179,12 +175,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) {
|
|||||||
requestMapConfig,
|
requestMapConfig,
|
||||||
params,
|
params,
|
||||||
context,
|
context,
|
||||||
(err, requestMapConfig, stats = { overviewsAddedToMapconfig: false }) => {
|
(err, requestMapConfig) => {
|
||||||
req.profiler.done('anonymous.getMapConfig');
|
|
||||||
|
|
||||||
stats.mapType = 'anonymous';
|
|
||||||
req.profiler.add(stats);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,6 @@ module.exports = class AttributesLayergroupController {
|
|||||||
|
|
||||||
function getFeatureAttributes (attributesBackend) {
|
function getFeatureAttributes (attributesBackend) {
|
||||||
return function getFeatureAttributesMiddleware (req, res, next) {
|
return function getFeatureAttributesMiddleware (req, res, next) {
|
||||||
req.profiler.start('windshaft.maplayer_attribute');
|
|
||||||
|
|
||||||
const { mapConfigProvider } = res.locals;
|
const { mapConfigProvider } = res.locals;
|
||||||
const { token } = res.locals;
|
const { token } = res.locals;
|
||||||
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
|
@ -62,8 +62,6 @@ module.exports = class AggregatedFeaturesLayergroupController {
|
|||||||
|
|
||||||
function getClusteredFeatures (clusterBackend) {
|
function getClusteredFeatures (clusterBackend) {
|
||||||
return function getFeatureAttributesMiddleware (req, res, next) {
|
return function getFeatureAttributesMiddleware (req, res, next) {
|
||||||
req.profiler.start('windshaft.maplayer_cluster_features');
|
|
||||||
|
|
||||||
const { mapConfigProvider } = res.locals;
|
const { mapConfigProvider } = res.locals;
|
||||||
const { user, token } = res.locals;
|
const { user, token } = res.locals;
|
||||||
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
|
@ -100,7 +100,6 @@ function getPreviewImageByCenter (previewBackend) {
|
|||||||
const options = { mapConfigProvider, format, width, height, zoom, center };
|
const options = { mapConfigProvider, format, width, height, zoom, center };
|
||||||
|
|
||||||
previewBackend.getImage(options, (err, image, stats = {}) => {
|
previewBackend.getImage(options, (err, image, stats = {}) => {
|
||||||
req.profiler.done(`render-${format}`);
|
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -133,7 +132,6 @@ function getPreviewImageByBoundingBox (previewBackend) {
|
|||||||
const options = { mapConfigProvider, format, width, height, bbox };
|
const options = { mapConfigProvider, format, width, height, bbox };
|
||||||
|
|
||||||
previewBackend.getImage(options, (err, image, stats = {}) => {
|
previewBackend.getImage(options, (err, image, stats = {}) => {
|
||||||
req.profiler.done(`render-${format}`);
|
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -292,7 +292,7 @@ function getImage ({ previewBackend, label }) {
|
|||||||
if (zoom !== undefined && center) {
|
if (zoom !== undefined && center) {
|
||||||
const options = { mapConfigProvider, format, width, height, zoom, center };
|
const options = { mapConfigProvider, format, width, height, zoom, center };
|
||||||
|
|
||||||
return previewBackend.getImage(options, (err, image, stats) => {
|
return previewBackend.getImage(options, (err, image, stats = {}) => {
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -309,9 +309,8 @@ function getImage ({ previewBackend, label }) {
|
|||||||
|
|
||||||
const options = { mapConfigProvider, format, width, height, bbox };
|
const options = { mapConfigProvider, format, width, height, bbox };
|
||||||
|
|
||||||
previewBackend.getImage(options, (err, image, stats) => {
|
previewBackend.getImage(options, (err, image, stats = {}) => {
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
req.profiler.done('render-' + format);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
|
@ -96,8 +96,6 @@ function getStatusCode (tile, format) {
|
|||||||
|
|
||||||
function getTile (tileBackend) {
|
function getTile (tileBackend) {
|
||||||
return function getTileMiddleware (req, res, next) {
|
return function getTileMiddleware (req, res, next) {
|
||||||
req.profiler.start(`windshaft.${req.params.layer ? 'maplayer_tile' : 'map_tile'}`);
|
|
||||||
|
|
||||||
const { mapConfigProvider } = res.locals;
|
const { mapConfigProvider } = res.locals;
|
||||||
const { token } = res.locals;
|
const { token } = res.locals;
|
||||||
const { layer, z, x, y, format } = req.params;
|
const { layer, z, x, y, format } = req.params;
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
module.exports = function authorize (authBackend) {
|
module.exports = function authorize (authBackend) {
|
||||||
return function authorizeMiddleware (req, res, next) {
|
return function authorizeMiddleware (req, res, next) {
|
||||||
authBackend.authorize(req, res, (err, authorized) => {
|
authBackend.authorize(req, res, (err, authorized) => {
|
||||||
req.profiler.done('authorize');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ module.exports = function checkJsonContentType () {
|
|||||||
return next(new Error('POST data must be of type application/json'));
|
return next(new Error('POST data must be of type application/json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
req.profiler.done('checkJsonContentTypeMiddleware');
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -7,8 +7,6 @@ module.exports = function dbConnSetup (pgConnection) {
|
|||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
|
|
||||||
pgConnection.setDBConn(user, res.locals, (err) => {
|
pgConnection.setDBConn(user, res.locals, (err) => {
|
||||||
req.profiler.done('dbConnSetup');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.message && err.message.indexOf('name not found') !== -1) {
|
if (err.message && err.message.indexOf('name not found') !== -1) {
|
||||||
err.http_status = 404;
|
err.http_status = 404;
|
||||||
|
@ -11,8 +11,6 @@ module.exports = function incrementMapViewCount (metadataBackend) {
|
|||||||
|
|
||||||
// Error won't blow up, just be logged.
|
// Error won't blow up, just be logged.
|
||||||
metadataBackend.incMapviewCount(user, statTag, (err) => {
|
metadataBackend.incMapviewCount(user, statTag, (err) => {
|
||||||
req.profiler.done('incMapviewCount');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.message = `Failed to increment mapview count for user '${user}'. ${err.message}`;
|
err.message = `Failed to increment mapview count for user '${user}'. ${err.message}`;
|
||||||
logger.warn({ error: err });
|
logger.warn({ error: err });
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = function initProfiler (isTemplateInstantiation) {
|
|
||||||
const operation = isTemplateInstantiation ? 'instance_template' : 'createmap';
|
|
||||||
|
|
||||||
return function initProfilerMiddleware (req, res, next) {
|
|
||||||
req.profiler.start(`windshaft-cartodb.${operation}_${req.method.toLowerCase()}`);
|
|
||||||
req.profiler.done(`${operation}.initProfilerMiddleware`);
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
};
|
|
@ -24,8 +24,6 @@ module.exports = function lzma () {
|
|||||||
delete req.query.lzma;
|
delete req.query.lzma;
|
||||||
Object.assign(req.query, JSON.parse(result));
|
Object.assign(req.query, JSON.parse(result));
|
||||||
|
|
||||||
req.profiler.done('lzma');
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(new Error('Error parsing lzma as JSON: ' + err));
|
next(new Error('Error parsing lzma as JSON: ' + err));
|
||||||
|
@ -4,7 +4,6 @@ module.exports = function mapError (options) {
|
|||||||
const { addContext = false, label = 'MAPS CONTROLLER' } = options;
|
const { addContext = false, label = 'MAPS CONTROLLER' } = options;
|
||||||
|
|
||||||
return function mapErrorMiddleware (err, req, res, next) {
|
return function mapErrorMiddleware (err, req, res, next) {
|
||||||
req.profiler.done('error');
|
|
||||||
const { mapConfig } = res.locals;
|
const { mapConfig } = res.locals;
|
||||||
|
|
||||||
if (addContext) {
|
if (addContext) {
|
||||||
|
@ -8,13 +8,18 @@ module.exports = function profiler (options) {
|
|||||||
|
|
||||||
return function profilerMiddleware (req, res, next) {
|
return function profilerMiddleware (req, res, next) {
|
||||||
const { logger } = res.locals;
|
const { logger } = res.locals;
|
||||||
|
const { id } = logger.bindings();
|
||||||
|
|
||||||
|
// TODO: stop using profiler and log stats instead of adding them to the profiler
|
||||||
req.profiler = new Profiler({
|
req.profiler = new Profiler({
|
||||||
statsd_client: statsClient,
|
statsd_client: statsClient,
|
||||||
profile: enabled
|
profile: enabled
|
||||||
});
|
});
|
||||||
|
|
||||||
|
req.profiler.start(id);
|
||||||
|
|
||||||
res.on('finish', () => {
|
res.on('finish', () => {
|
||||||
|
req.profiler.done('response');
|
||||||
logger.info({ stats: req.profiler.toJSON() });
|
logger.info({ stats: req.profiler.toJSON() });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
module.exports = function sendResponse () {
|
module.exports = function sendResponse () {
|
||||||
return function sendResponseMiddleware (req, res, next) {
|
return function sendResponseMiddleware (req, res, next) {
|
||||||
req.profiler.done('res');
|
|
||||||
|
|
||||||
res.status(res.statusCode);
|
res.status(res.statusCode);
|
||||||
|
|
||||||
if (Buffer.isBuffer(res.body)) {
|
if (Buffer.isBuffer(res.body)) {
|
||||||
|
@ -166,8 +166,6 @@ function updateTemplate ({ templateMaps }) {
|
|||||||
|
|
||||||
function retrieveTemplate ({ templateMaps }) {
|
function retrieveTemplate ({ templateMaps }) {
|
||||||
return function retrieveTemplateMiddleware (req, res, next) {
|
return function retrieveTemplateMiddleware (req, res, next) {
|
||||||
req.profiler.start('windshaft-cartodb.get_template');
|
|
||||||
|
|
||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
const templateId = templateName(req.params.template_id);
|
const templateId = templateName(req.params.template_id);
|
||||||
|
|
||||||
@ -195,8 +193,6 @@ function retrieveTemplate ({ templateMaps }) {
|
|||||||
|
|
||||||
function destroyTemplate ({ templateMaps }) {
|
function destroyTemplate ({ templateMaps }) {
|
||||||
return function destroyTemplateMiddleware (req, res, next) {
|
return function destroyTemplateMiddleware (req, res, next) {
|
||||||
req.profiler.start('windshaft-cartodb.delete_template');
|
|
||||||
|
|
||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
const templateId = templateName(req.params.template_id);
|
const templateId = templateName(req.params.template_id);
|
||||||
|
|
||||||
@ -215,8 +211,6 @@ function destroyTemplate ({ templateMaps }) {
|
|||||||
|
|
||||||
function listTemplates ({ templateMaps }) {
|
function listTemplates ({ templateMaps }) {
|
||||||
return function listTemplatesMiddleware (req, res, next) {
|
return function listTemplatesMiddleware (req, res, next) {
|
||||||
req.profiler.start('windshaft-cartodb.get_template_list');
|
|
||||||
|
|
||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
|
|
||||||
templateMaps.listTemplates(user, (err, templateIds) => {
|
templateMaps.listTemplates(user, (err, templateIds) => {
|
||||||
|
@ -4,7 +4,6 @@ const cleanUpQueryParams = require('../middlewares/clean-up-query-params');
|
|||||||
const credentials = require('../middlewares/credentials');
|
const credentials = require('../middlewares/credentials');
|
||||||
const dbConnSetup = require('../middlewares/db-conn-setup');
|
const dbConnSetup = require('../middlewares/db-conn-setup');
|
||||||
const authorize = require('../middlewares/authorize');
|
const authorize = require('../middlewares/authorize');
|
||||||
const initProfiler = require('../middlewares/init-profiler');
|
|
||||||
const checkJsonContentType = require('../middlewares/check-json-content-type');
|
const checkJsonContentType = require('../middlewares/check-json-content-type');
|
||||||
const incrementMapViewCount = require('../middlewares/increment-map-view-count');
|
const incrementMapViewCount = require('../middlewares/increment-map-view-count');
|
||||||
const augmentLayergroupData = require('../middlewares/augment-layergroup-data');
|
const augmentLayergroupData = require('../middlewares/augment-layergroup-data');
|
||||||
@ -74,7 +73,6 @@ module.exports = class NamedMapController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
middlewares () {
|
middlewares () {
|
||||||
const isTemplateInstantiation = true;
|
|
||||||
const useTemplateHash = true;
|
const useTemplateHash = true;
|
||||||
const includeQuery = false;
|
const includeQuery = false;
|
||||||
const label = 'NAMED MAP LAYERGROUP';
|
const label = 'NAMED MAP LAYERGROUP';
|
||||||
@ -100,7 +98,6 @@ module.exports = class NamedMapController {
|
|||||||
dbConnSetup(this.pgConnection),
|
dbConnSetup(this.pgConnection),
|
||||||
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED),
|
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED),
|
||||||
cleanUpQueryParams(['aggregation']),
|
cleanUpQueryParams(['aggregation']),
|
||||||
initProfiler(isTemplateInstantiation),
|
|
||||||
checkJsonContentType(),
|
checkJsonContentType(),
|
||||||
checkInstantiteLayergroup(),
|
checkInstantiteLayergroup(),
|
||||||
getTemplate(
|
getTemplate(
|
||||||
@ -150,8 +147,6 @@ function checkInstantiteLayergroup () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.profiler.done('checkInstantiteLayergroup');
|
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -187,9 +182,6 @@ function getTemplate (
|
|||||||
);
|
);
|
||||||
|
|
||||||
mapConfigProvider.getMapConfig((err, mapConfig, rendererParams, context, stats = {}) => {
|
mapConfigProvider.getMapConfig((err, mapConfig, rendererParams, context, stats = {}) => {
|
||||||
req.profiler.done('named.getMapConfig');
|
|
||||||
|
|
||||||
stats.mapType = 'named';
|
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -67,9 +67,8 @@ function getTile ({ tileBackend, label }) {
|
|||||||
const { layer, z, x, y, format } = req.params;
|
const { layer, z, x, y, format } = req.params;
|
||||||
const params = { layer, z, x, y, format };
|
const params = { layer, z, x, y, format };
|
||||||
|
|
||||||
tileBackend.getTile(mapConfigProvider, params, (err, tile, headers, stats) => {
|
tileBackend.getTile(mapConfigProvider, params, (err, tile, headers, stats = {}) => {
|
||||||
req.profiler.add(stats);
|
req.profiler.add(stats);
|
||||||
req.profiler.done('render-' + format);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
|
@ -133,8 +133,6 @@ AuthBackend.prototype.authorize = function (req, res, callback) {
|
|||||||
|
|
||||||
if (isAuthorizedByApikey) {
|
if (isAuthorizedByApikey) {
|
||||||
return this.pgConnection.setDBAuth(user, res.locals, 'regular', function (err) {
|
return this.pgConnection.setDBAuth(user, res.locals, 'regular', function (err) {
|
||||||
req.profiler.done('setDBAuth');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -150,8 +148,6 @@ AuthBackend.prototype.authorize = function (req, res, callback) {
|
|||||||
|
|
||||||
if (isAuthorizedBySigner) {
|
if (isAuthorizedBySigner) {
|
||||||
return this.pgConnection.setDBAuth(user, res.locals, 'master', function (err) {
|
return this.pgConnection.setDBAuth(user, res.locals, 'master', function (err) {
|
||||||
req.profiler.done('setDBAuth');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -163,8 +159,6 @@ AuthBackend.prototype.authorize = function (req, res, callback) {
|
|||||||
// if no signer name was given, use default api key
|
// if no signer name was given, use default api key
|
||||||
if (!res.locals.signer) {
|
if (!res.locals.signer) {
|
||||||
return this.pgConnection.setDBAuth(user, res.locals, 'default', function (err) {
|
return this.pgConnection.setDBAuth(user, res.locals, 'default', function (err) {
|
||||||
req.profiler.done('setDBAuth');
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ function getPGTypeName (pgType) {
|
|||||||
|
|
||||||
module.exports = class BaseDataview {
|
module.exports = class BaseDataview {
|
||||||
getResult (psql, override, callback) {
|
getResult (psql, override, callback) {
|
||||||
this.sql(psql, override, (err, query, flags = null) => {
|
this.sql(psql, override, (err, query) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -36,20 +36,7 @@ module.exports = class BaseDataview {
|
|||||||
result = this.format(result, override);
|
result = this.format(result, override);
|
||||||
result.type = this.getType();
|
result.type = this.getType();
|
||||||
|
|
||||||
// Overviews logging
|
return callback(null, result);
|
||||||
const stats = {};
|
|
||||||
|
|
||||||
if (flags && flags.usesOverviews !== undefined) {
|
|
||||||
stats.usesOverviews = flags.usesOverviews;
|
|
||||||
} else {
|
|
||||||
stats.usesOverviews = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getType) {
|
|
||||||
stats.dataviewType = this.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
return callback(null, result, stats);
|
|
||||||
}, true); // use read-only transaction
|
}, true); // use read-only transaction
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ Aggregation.prototype.sql = function (psql, override, callback) {
|
|||||||
|
|
||||||
debug(aggregationSql);
|
debug(aggregationSql);
|
||||||
|
|
||||||
return callback(null, aggregationSql, { usesOverviews: true });
|
return callback(null, aggregationSql);
|
||||||
};
|
};
|
||||||
|
|
||||||
var aggregationFnQueryTpl = {
|
var aggregationFnQueryTpl = {
|
||||||
|
@ -76,5 +76,5 @@ Formula.prototype.sql = function (psql, override, callback) {
|
|||||||
|
|
||||||
debug(formulaSql);
|
debug(formulaSql);
|
||||||
|
|
||||||
return callback(null, formulaSql, { usesOverviews: true });
|
return callback(null, formulaSql);
|
||||||
};
|
};
|
||||||
|
@ -179,7 +179,7 @@ Histogram.prototype.sql = function (psql, override, callback) {
|
|||||||
|
|
||||||
var histogramSql = this._buildQuery(override);
|
var histogramSql = this._buildQuery(override);
|
||||||
|
|
||||||
return callback(null, histogramSql, { usesOverviews: true });
|
return callback(null, histogramSql);
|
||||||
};
|
};
|
||||||
|
|
||||||
Histogram.prototype._buildQuery = function (override) {
|
Histogram.prototype._buildQuery = function (override) {
|
||||||
|
@ -25,58 +25,50 @@ MapConfigOverviewsAdapter.prototype.getMapConfig = function (user, requestMapCon
|
|||||||
|
|
||||||
layers.forEach(layer => augmentLayersQueue.defer(this._augmentLayer.bind(this), user, layer, analysesResults));
|
layers.forEach(layer => augmentLayersQueue.defer(this._augmentLayer.bind(this), user, layer, analysesResults));
|
||||||
|
|
||||||
augmentLayersQueue.awaitAll(function layersAugmentQueueFinish (err, results) {
|
augmentLayersQueue.awaitAll(function layersAugmentQueueFinish (err, layers) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const layers = results.map(result => result.layer);
|
|
||||||
const overviewsAddedToMapconfig = results.some(result => result.overviewsAddedToMapconfig);
|
|
||||||
|
|
||||||
if (!layers || layers.length === 0) {
|
if (!layers || layers.length === 0) {
|
||||||
return callback(new Error('Missing layers array from layergroup config'));
|
return callback(new Error('Missing layers array from layergroup config'));
|
||||||
}
|
}
|
||||||
|
|
||||||
requestMapConfig.layers = layers;
|
requestMapConfig.layers = layers;
|
||||||
|
|
||||||
const stats = { overviewsAddedToMapconfig };
|
return callback(null, requestMapConfig);
|
||||||
|
|
||||||
return callback(null, requestMapConfig, stats);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MapConfigOverviewsAdapter.prototype._augmentLayer = function (user, layer, analysesResults, callback) {
|
MapConfigOverviewsAdapter.prototype._augmentLayer = function (user, layer, analysesResults, callback) {
|
||||||
let overviewsAddedToMapconfig = false;
|
|
||||||
if (layer.type !== 'mapnik' && layer.type !== 'cartodb') {
|
if (layer.type !== 'mapnik' && layer.type !== 'cartodb') {
|
||||||
return callback(null, { layer, overviewsAddedToMapconfig });
|
return callback(null, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.overviewsMetadataBackend.getOverviewsMetadata(user, layer.options.sql, (err, metadata) => {
|
this.overviewsMetadataBackend.getOverviewsMetadata(user, layer.options.sql, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err, { layer, overviewsAddedToMapconfig });
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isEmpty(metadata)) {
|
if (_.isEmpty(metadata)) {
|
||||||
return callback(null, { layer, overviewsAddedToMapconfig });
|
return callback(null, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
var filters = getFilters(analysesResults, layer);
|
var filters = getFilters(analysesResults, layer);
|
||||||
|
|
||||||
overviewsAddedToMapconfig = true;
|
|
||||||
|
|
||||||
if (!filters) {
|
if (!filters) {
|
||||||
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
|
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
|
||||||
overviews: metadata
|
overviews: metadata
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return callback(null, { layer, overviewsAddedToMapconfig });
|
return callback(null, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
var unfilteredQuery = getUnfilteredQuery(analysesResults, layer);
|
var unfilteredQuery = getUnfilteredQuery(analysesResults, layer);
|
||||||
|
|
||||||
this.filterStatsBackend.getFilterStats(user, unfilteredQuery, filters, function (err, stats) {
|
this.filterStatsBackend.getFilterStats(user, unfilteredQuery, filters, function (err, stats) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(null, { layer, overviewsAddedToMapconfig });
|
return callback(null, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
|
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
|
||||||
@ -84,7 +76,7 @@ MapConfigOverviewsAdapter.prototype._augmentLayer = function (user, layer, analy
|
|||||||
filter_stats: stats
|
filter_stats: stats
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return callback(null, { layer, overviewsAddedToMapconfig });
|
return callback(null, layer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user