diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index 494620aa..b05eac4e 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -83,7 +83,7 @@ NamedMapsController.prototype.register = function(app) { prepareLayerFilterFromPreviewLayers(staticOptions), getStaticImageOptions({ tablesExtentApi: this.tablesExtentApi }), getImage(staticOptions), - this.incrementMapViews(), + incrementMapViews({ metadataBackend: this.metadataBackend }), this.setSurrogateKey(), this.setCacheChannelHeader(), this.setLastModifiedHeader(), @@ -366,7 +366,7 @@ function incrementMapViewsError (ctx) { return `ERROR: failed to increment mapview count for user '${ctx.user}': ${ctx.err}`; } -NamedMapsController.prototype.incrementMapViews = function () { +function incrementMapViews ({ metadataBackend }) { return function incrementMapViewsMiddleware(req, res, next) { const { user, namedMapProvider } = res.locals; @@ -378,7 +378,7 @@ NamedMapsController.prototype.incrementMapViews = function () { const statTag = mapConfig.obj().stat_tag; - this.metadataBackend.incMapviewCount(user, statTag, (err) => { + metadataBackend.incMapviewCount(user, statTag, (err) => { if (err) { global.logger.log(incrementMapViewsError({ user, err })); } @@ -386,8 +386,8 @@ NamedMapsController.prototype.incrementMapViews = function () { next(); }); }); - }.bind(this); -}; + }; +} function templateZoomCenter(view) { if (view.zoom !== undefined && view.center) {