Extract increment map view count middleware
This commit is contained in:
parent
b68d2d9115
commit
1d54a8dccd
@ -10,6 +10,7 @@ const dbConnSetup = require('../../middleware/db-conn-setup');
|
|||||||
const authorize = require('../../middleware/authorize');
|
const authorize = require('../../middleware/authorize');
|
||||||
const initProfiler = require('./middlewares/init-profiler');
|
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 cacheControlHeader = require('../../middleware/cache-control-header');
|
const cacheControlHeader = require('../../middleware/cache-control-header');
|
||||||
const cacheChannelHeader = require('../../middleware/cache-channel-header');
|
const cacheChannelHeader = require('../../middleware/cache-channel-header');
|
||||||
const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
|
const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
|
||||||
@ -215,23 +216,6 @@ function createLayergroup (mapBackend, userLimitsApi, pgConnection, affectedTabl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function incrementMapViewCount (metadataBackend) {
|
|
||||||
return function incrementMapViewCountMiddleware(req, res, next) {
|
|
||||||
const { mapConfig, user } = res.locals;
|
|
||||||
|
|
||||||
// Error won't blow up, just be logged.
|
|
||||||
metadataBackend.incMapviewCount(user, mapConfig.obj().stat_tag, (err) => {
|
|
||||||
req.profiler.done('incMapviewCount');
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
global.logger.log(`ERROR: failed to increment mapview count for user '${user}': ${err.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function augmentLayergroupData () {
|
function augmentLayergroupData () {
|
||||||
return function augmentLayergroupDataMiddleware (req, res, next) {
|
return function augmentLayergroupDataMiddleware (req, res, next) {
|
||||||
const layergroup = res.body;
|
const layergroup = res.body;
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
module.exports = function incrementMapViewCount (metadataBackend) {
|
||||||
|
return function incrementMapViewCountMiddleware(req, res, next) {
|
||||||
|
const { mapConfig, user } = res.locals;
|
||||||
|
|
||||||
|
// Error won't blow up, just be logged.
|
||||||
|
metadataBackend.incMapviewCount(user, mapConfig.obj().stat_tag, (err) => {
|
||||||
|
req.profiler.done('incMapviewCount');
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
global.logger.log(`ERROR: failed to increment mapview count for user '${user}': ${err.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
@ -6,6 +6,7 @@ const dbConnSetup = require('../../middleware/db-conn-setup');
|
|||||||
const authorize = require('../../middleware/authorize');
|
const authorize = require('../../middleware/authorize');
|
||||||
const initProfiler = require('./middlewares/init-profiler');
|
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 cacheControlHeader = require('../../middleware/cache-control-header');
|
const cacheControlHeader = require('../../middleware/cache-control-header');
|
||||||
const cacheChannelHeader = require('../../middleware/cache-channel-header');
|
const cacheChannelHeader = require('../../middleware/cache-channel-header');
|
||||||
const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
|
const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
|
||||||
@ -221,23 +222,6 @@ function instantiateLayergroup (mapBackend, userLimitsApi, pgConnection, affecte
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function incrementMapViewCount (metadataBackend) {
|
|
||||||
return function incrementMapViewCountMiddleware(req, res, next) {
|
|
||||||
const { mapConfig, user } = res.locals;
|
|
||||||
|
|
||||||
// Error won't blow up, just be logged.
|
|
||||||
metadataBackend.incMapviewCount(user, mapConfig.obj().stat_tag, (err) => {
|
|
||||||
req.profiler.done('incMapviewCount');
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
global.logger.log(`ERROR: failed to increment mapview count for user '${user}': ${err.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function augmentLayergroupData () {
|
function augmentLayergroupData () {
|
||||||
return function augmentLayergroupDataMiddleware (req, res, next) {
|
return function augmentLayergroupDataMiddleware (req, res, next) {
|
||||||
const layergroup = res.body;
|
const layergroup = res.body;
|
||||||
|
Loading…
Reference in New Issue
Block a user