diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index ced0f40674..6c03674483 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -48,14 +48,19 @@ middleware.applyCSRF = csrf(); middleware.ensureLoggedIn = ensureLoggedIn.ensureLoggedIn(nconf.get('relative_path') + '/login'); middleware.pageView = function(req, res, next) { + analytics.pageView(req.ip); + if (req.user) { user.updateLastOnlineTime(req.user.uid); - user.updateOnlineUsers(req.user.uid); + if (req.path.startsWith('/api/users') || req.path.startsWith('/users')) { + user.updateOnlineUsers(req.user.uid, next); + } else { + user.updateOnlineUsers(req.user.uid); + next(); + } + } else { + next(); } - - analytics.pageView(req.ip); - - next(); }; middleware.redirectToAccountIfLoggedIn = function(req, res, next) {