cache popular route for anons

v1.18.x
psychobunny 11 years ago
parent 15052143d3
commit 071be4ae7f

@ -27,11 +27,19 @@ categoriesController.recent = function(req, res, next) {
}); });
}; };
var anonCache = {}, lastUpdateTime = 0;
categoriesController.popular = function(req, res, next) { categoriesController.popular = function(req, res, next) {
var uid = req.user ? req.user.uid : 0; var uid = req.user ? req.user.uid : 0;
var term = req.params.term || 'daily'; var term = req.params.term || 'daily';
if (uid === 0) {
if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) {
return res.render('popular', anonCache[term]);
}
}
topics.getPopular(term, uid, meta.config.topicsPerList, function(err, data) { topics.getPopular(term, uid, meta.config.topicsPerList, function(err, data) {
if (err) { if (err) {
return next(err); return next(err);
@ -40,6 +48,11 @@ categoriesController.popular = function(req, res, next) {
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) { plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) {
if (uid === 0) {
anonCache[term] = data;
lastUpdateTime = Date.now();
}
res.render('popular', data); res.render('popular', data);
}); });
}); });

Loading…
Cancel
Save