From 071be4ae7f29820e25819b283465717583497aa7 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sat, 6 Sep 2014 01:47:58 -0400 Subject: [PATCH] cache popular route for anons --- src/controllers/categories.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/controllers/categories.js b/src/controllers/categories.js index f7557210fb..f9039e2bd3 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -27,11 +27,19 @@ categoriesController.recent = function(req, res, next) { }); }; +var anonCache = {}, lastUpdateTime = 0; + categoriesController.popular = function(req, res, next) { var uid = req.user ? req.user.uid : 0; 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) { if (err) { return next(err); @@ -40,6 +48,11 @@ categoriesController.popular = function(req, res, next) { data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) { + if (uid === 0) { + anonCache[term] = data; + lastUpdateTime = Date.now(); + } + res.render('popular', data); }); });