mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
popular topics will use topic creation time
This commit is contained in:
@@ -35,8 +35,13 @@ 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 terms = {
|
||||||
var term = req.params.term || 'daily';
|
daily: 'day',
|
||||||
|
weekly: 'week',
|
||||||
|
monthly: 'month',
|
||||||
|
alltime: 'alltime'
|
||||||
|
};
|
||||||
|
var term = terms[req.params.term] || 'day';
|
||||||
|
|
||||||
if (uid === 0) {
|
if (uid === 0) {
|
||||||
if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) {
|
if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) {
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ var async = require('async'),
|
|||||||
|
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
var terms = {
|
|
||||||
daily: 'day',
|
|
||||||
weekly: 'week',
|
|
||||||
monthly: 'month'
|
|
||||||
};
|
|
||||||
|
|
||||||
Topics.getPopular = function(term, uid, count, callback) {
|
Topics.getPopular = function(term, uid, count, callback) {
|
||||||
count = parseInt(count, 10) || 20;
|
count = parseInt(count, 10) || 20;
|
||||||
@@ -20,11 +15,9 @@ module.exports = function(Topics) {
|
|||||||
return getAllTimePopular(uid, count, callback);
|
return getAllTimePopular(uid, count, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
var since = terms[term] || 'day';
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
Topics.getLatestTids(0, -1, since, next);
|
Topics.getLatestTidsFromSet('topics:tid', 0, -1, term, next);
|
||||||
},
|
},
|
||||||
function(tids, next) {
|
function(tids, next) {
|
||||||
getTopics(tids, uid, count, next);
|
getTopics(tids, uid, count, next);
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
|
winston = require('winston'),
|
||||||
db = require('../database');
|
db = require('../database');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
var terms = {
|
var terms = {
|
||||||
day: 86400000,
|
day: 86400000,
|
||||||
@@ -18,7 +17,7 @@ module.exports = function(Topics) {
|
|||||||
Topics.getLatestTopics = function(uid, start, end, term, callback) {
|
Topics.getLatestTopics = function(uid, start, end, term, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.getLatestTids(start, end, term, next);
|
Topics.getLatestTidsFromSet('topics:recent', start, end, term, next);
|
||||||
},
|
},
|
||||||
function(tids, next) {
|
function(tids, next) {
|
||||||
Topics.getTopics(tids, uid, next);
|
Topics.getTopics(tids, uid, next);
|
||||||
@@ -30,6 +29,11 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getLatestTids = function(start, end, term, callback) {
|
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;
|
var since = terms.day;
|
||||||
if (terms[term]) {
|
if (terms[term]) {
|
||||||
since = terms[term];
|
since = terms[term];
|
||||||
@@ -37,7 +41,7 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
|
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) {
|
Topics.updateTimestamp = function(tid, timestamp, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user