Fix view logging exceptions and log errors when processing trending data #659
2 changed files with 54 additions and 35 deletions
|
@ -1,3 +1,4 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../models');
|
||||
const httpContext = require('express-http-context');
|
||||
|
||||
|
@ -6,6 +7,18 @@ function logMetricsMiddleware(req, res, next) {
|
|||
const userAgent = req.get('user-agent');
|
||||
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({
|
||||
time: Date.now(),
|
||||
isInternal: /node\-fetch/.test(userAgent),
|
||||
|
@ -16,7 +29,7 @@ function logMetricsMiddleware(req, res, next) {
|
|||
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
||||
request: req.url,
|
||||
routeData: JSON.stringify(httpContext.get('routeData')),
|
||||
referrer: req.get('referrer'),
|
||||
referrer,
|
||||
userAgent,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,7 +6,10 @@ const {
|
|||
getWeight,
|
||||
} = require('server/models/utils/trendingAnalysis');
|
||||
|
||||
const logger = require('winston');
|
||||
|
||||
module.exports = async () => {
|
||||
try {
|
||||
const claims = await db.Trending.getTrendingClaims();
|
||||
const claimViews = await db.Views.getUniqueViews();
|
||||
|
||||
|
@ -49,4 +52,7 @@ module.exports = async () => {
|
|||
|
||||
db.Trending.create(trendingData);
|
||||
}
|
||||
} catch(e) {
|
||||
logger.error('Error processing trending content:', e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue