From ca56df5cfe44b919aba895b16c9a0a6e11ba3b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 5 Mar 2018 18:28:52 +0100 Subject: [PATCH] Middlewarify attributes endpoint --- lib/cartodb/controllers/layergroup.js | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 502ba16b..3122113e 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -79,7 +79,8 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.attributes.bind(this) + this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + this.attributes(this.attributesBackend) ); app.get( @@ -229,30 +230,23 @@ LayergroupController.prototype.dataviewSearch = function (dataviewBackend) { }.bind(this); }; -LayergroupController.prototype.attributes = function(req, res, next) { - var self = this; +LayergroupController.prototype.attributes = function (attributesBackend) { + return function attributesMiddleware (req, res, next) { + req.profiler.start('windshaft.maplayer_attribute'); - req.profiler.start('windshaft.maplayer_attribute'); + const { mapConfigProvider } = res.locals; - step( - function retrieveFeatureAttributes() { - var mapConfigProvider = new MapStoreMapConfigProvider( - self.mapStore, res.locals.user, self.userLimitsApi, res.locals - ); - self.attributesBackend.getFeatureAttributes(mapConfigProvider, res.locals, false, this); - }, - function finish(err, tile, stats) { + attributesBackend.getFeatureAttributes(mapConfigProvider, res.locals, false, (err, tile, stats) => { req.profiler.add(stats || {}); if (err) { err.label = 'GET ATTRIBUTES'; - next(err); - } else { - self.sendResponse(req, res, tile, 200); + return next(err); } - } - ); + this.sendResponse(req, res, tile, 200); + }); + }.bind(this); }; // Gets a tile for a given token and set of tile ZXY coords. (OSM style)