2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-28 19:01:23 +08:00
|
|
|
module.exports = function incrementMapViewCount (metadataBackend) {
|
2019-10-22 01:07:24 +08:00
|
|
|
return function incrementMapViewCountMiddleware (req, res, next) {
|
2020-06-02 15:00:45 +08:00
|
|
|
const { mapConfig, user, logger } = res.locals;
|
2020-05-26 19:15:35 +08:00
|
|
|
const statTag = mapConfig.obj().stat_tag;
|
|
|
|
|
2020-05-29 22:06:16 +08:00
|
|
|
if (statTag) {
|
|
|
|
res.set('Carto-Stat-Tag', `${statTag}`);
|
|
|
|
}
|
2018-03-28 19:01:23 +08:00
|
|
|
|
|
|
|
// Error won't blow up, just be logged.
|
2020-05-26 19:15:35 +08:00
|
|
|
metadataBackend.incMapviewCount(user, statTag, (err) => {
|
2018-03-28 19:01:23 +08:00
|
|
|
req.profiler.done('incMapviewCount');
|
|
|
|
|
|
|
|
if (err) {
|
2020-06-02 15:00:45 +08:00
|
|
|
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
|
2018-03-28 19:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|