mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
cache popular route for anons
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user