Fix view logging exceptions and log errors when processing trending data
This commit is contained in:
parent
828e8dce70
commit
af8e7e7044
2 changed files with 54 additions and 35 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
const logger = require('winston');
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const httpContext = require('express-http-context');
|
const httpContext = require('express-http-context');
|
||||||
|
|
||||||
|
@ -6,6 +7,18 @@ function logMetricsMiddleware(req, res, next) {
|
||||||
const userAgent = req.get('user-agent');
|
const userAgent = req.get('user-agent');
|
||||||
const routePath = httpContext.get('routePath');
|
const routePath = httpContext.get('routePath');
|
||||||
|
|
||||||
|
let referrer = req.get('referrer');
|
||||||
|
|
||||||
|
if(referrer.length > 255) {
|
||||||
|
// Attempt to "safely" clamp long URLs
|
||||||
|
referrer = /(.*?)#.*/.exec(referrer)[1];
|
||||||
|
|
||||||
|
if(referrer.length > 255) {
|
||||||
|
logger.warn('Request refferer exceeds 255 characters:', referrer);
|
||||||
|
referrer = referrer.substring(0, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.Metrics.create({
|
db.Metrics.create({
|
||||||
time: Date.now(),
|
time: Date.now(),
|
||||||
isInternal: /node\-fetch/.test(userAgent),
|
isInternal: /node\-fetch/.test(userAgent),
|
||||||
|
@ -16,7 +29,7 @@ function logMetricsMiddleware(req, res, next) {
|
||||||
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
||||||
request: req.url,
|
request: req.url,
|
||||||
routeData: JSON.stringify(httpContext.get('routeData')),
|
routeData: JSON.stringify(httpContext.get('routeData')),
|
||||||
referrer: req.get('referrer'),
|
referrer,
|
||||||
userAgent,
|
userAgent,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,10 @@ const {
|
||||||
getWeight,
|
getWeight,
|
||||||
} = require('server/models/utils/trendingAnalysis');
|
} = require('server/models/utils/trendingAnalysis');
|
||||||
|
|
||||||
|
const logger = require('winston');
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
|
try {
|
||||||
const claims = await db.Trending.getTrendingClaims();
|
const claims = await db.Trending.getTrendingClaims();
|
||||||
const claimViews = await db.Views.getUniqueViews();
|
const claimViews = await db.Views.getUniqueViews();
|
||||||
|
|
||||||
|
@ -49,4 +52,7 @@ module.exports = async () => {
|
||||||
|
|
||||||
db.Trending.create(trendingData);
|
db.Trending.create(trendingData);
|
||||||
}
|
}
|
||||||
|
} catch(e) {
|
||||||
|
logger.error('Error processing trending content:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue