popular topics will use topic creation time

v1.18.x
barisusakli 10 years ago
parent 2d4383c7b0
commit c1ac92ac19

@ -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) {

@ -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);

@ -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) {

Loading…
Cancel
Save