This commit is contained in:
Baris Usakli
2017-10-19 13:53:05 -04:00
parent 8733f51f86
commit 19dc7da42f
7 changed files with 80 additions and 68 deletions

View File

@@ -1,12 +1,13 @@
'use strict';
var async = require('async');
var nconf = require('nconf');
var topics = require('../topics');
var meta = require('../meta');
var helpers = require('./helpers');
var popularController = {};
var popularController = module.exports;
var anonCache = {};
var lastUpdateTime = 0;
@@ -38,36 +39,35 @@ popularController.get = function (req, res, next) {
}
}
topics.getPopular(term, req.uid, meta.config.topicsPerList, function (err, topics) {
if (err) {
return next(err);
}
async.waterfall([
function (next) {
topics.getPopular(term, req.uid, meta.config.topicsPerList, next);
},
function (topics) {
var data = {
topics: topics,
'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1,
rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss',
title: '[[pages:popular-' + term + ']]',
term: term,
};
var data = {
topics: topics,
'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1,
rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss',
title: '[[pages:popular-' + term + ']]',
term: term,
};
if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
var breadcrumbs = [{ text: termToBreadcrumb[term] }];
if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
var breadcrumbs = [{ text: termToBreadcrumb[term] }];
if (req.params.term) {
breadcrumbs.unshift({ text: '[[global:header.popular]]', url: '/popular' });
}
if (req.params.term) {
breadcrumbs.unshift({ text: '[[global:header.popular]]', url: '/popular' });
data.breadcrumbs = helpers.buildBreadcrumbs(breadcrumbs);
}
data.breadcrumbs = helpers.buildBreadcrumbs(breadcrumbs);
}
if (!req.uid) {
anonCache[term] = data;
lastUpdateTime = Date.now();
}
if (!req.uid) {
anonCache[term] = data;
lastUpdateTime = Date.now();
}
res.render('popular', data);
});
res.render('popular', data);
},
], next);
};
module.exports = popularController;