Skip to content

Node.js based forum software built for the modern web

popular topics will use topic creation time

barisusaklic1ac92ac199f
diff --git a/src/controllers/categories.js b/src/controllers/categories.js
index 0a06dafce1..14abb6f260 100644
--- a/src/controllers/categories.js
+++ b/src/controllers/categories.js
@@ -35,8 +35,13 @@ var anonCache = {}, lastUpdateTime = 0;
categoriesController.popular = function(req, res, next) {
var uid = req.user ? req.user.uid : 0;
-
- var term = req.params.term || 'daily';
+ var terms = {
+ daily: 'day',
+ weekly: 'week',
+ monthly: 'month',
+ alltime: 'alltime'
+ };
+ var term = terms[req.params.term] || 'day';
if (uid === 0) {
if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) {
diff --git a/src/topics/popular.js b/src/topics/popular.js
index 710dc27e7c..1f8ff31bf3 100644
--- a/src/topics/popular.js
+++ b/src/topics/popular.js
@@ -7,11 +7,6 @@ var async = require('async'),
module.exports = function(Topics) {
- var terms = {
- daily: 'day',
- weekly: 'week',
- monthly: 'month'
- };
Topics.getPopular = function(term, uid, count, callback) {
count = parseInt(count, 10) || 20;
@@ -20,11 +15,9 @@ module.exports = function(Topics) {
return getAllTimePopular(uid, count, callback);
}
- var since = terms[term] || 'day';
-
async.waterfall([
function(next) {
- Topics.getLatestTids(0, -1, since, next);
+ Topics.getLatestTidsFromSet('topics:tid', 0, -1, term, next);
},
function(tids, next) {
getTopics(tids, uid, count, next);
diff --git a/src/topics/recent.js b/src/topics/recent.js
index b316aa65a5..19c3debd03 100644
--- a/src/topics/recent.js
+++ b/src/topics/recent.js
@@ -3,10 +3,9 @@
'use strict';
var async = require('async'),
+ winston = require('winston'),
db = require('../database');
-
-
module.exports = function(Topics) {
var terms = {
day: 86400000,
@@ -18,7 +17,7 @@ module.exports = function(Topics) {
Topics.getLatestTopics = function(uid, start, end, term, callback) {
async.waterfall([
function (next) {
- Topics.getLatestTids(start, end, term, next);
+ Topics.getLatestTidsFromSet('topics:recent', start, end, term, next);
},
function(tids, next) {
Topics.getTopics(tids, uid, next);
@@ -30,6 +29,11 @@ module.exports = function(Topics) {
};
Topics.getLatestTids = function(start, end, term, callback) {
+ winston.warn('[deprecation warning] please use Topics.getLatestTidsFromSet("topics:recent")');
+ Topics.getLatestTidsFromSet('topics:recent', start, end, term, callback);
+ };
+
+ Topics.getLatestTidsFromSet = function(set, start, end, term, callback) {
var since = terms.day;
if (terms[term]) {
since = terms[term];
@@ -37,7 +41,7 @@ module.exports = function(Topics) {
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
- db.getSortedSetRevRangeByScore('topics:recent', start, count, '+inf', Date.now() - since, callback);
+ db.getSortedSetRevRangeByScore(set, start, count, '+inf', Date.now() - since, callback);
};
Topics.updateTimestamp = function(tid, timestamp, callback) {