Files
NodeBB/src/topics/recent.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-03-21 17:04:15 -04:00
'use strict';
2014-09-19 15:54:13 -04:00
var async = require('async'),
winston = require('winston'),
2014-09-19 15:54:13 -04:00
db = require('../database');
2014-03-21 17:04:15 -04:00
module.exports = function(Topics) {
2014-09-03 15:16:41 -04:00
var terms = {
day: 86400000,
week: 604800000,
month: 2592000000,
year: 31104000000
};
2014-03-21 17:04:15 -04:00
Topics.getLatestTopics = function(uid, start, stop, term, callback) {
async.waterfall([
function (next) {
Topics.getLatestTidsFromSet('topics:recent', start, stop, term, next);
},
function(tids, next) {
Topics.getTopics(tids, uid, next);
},
function(topics, next) {
next(null, {topics: topics, nextStart: stop + 1});
2014-03-21 17:04:15 -04:00
}
], callback);
2014-03-21 17:04:15 -04:00
};
Topics.getLatestTids = function(start, stop, term, callback) {
winston.warn('[deprecation warning] please use Topics.getLatestTidsFromSet("topics:recent")');
Topics.getLatestTidsFromSet('topics:recent', start, stop, term, callback);
};
Topics.getLatestTidsFromSet = function(set, start, stop, term, callback) {
2014-03-21 17:04:15 -04:00
var since = terms.day;
2014-09-03 15:16:41 -04:00
if (terms[term]) {
2014-03-21 17:04:15 -04:00
since = terms[term];
}
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
2014-03-21 17:04:15 -04:00
db.getSortedSetRevRangeByScore(set, start, count, '+inf', Date.now() - since, callback);
2014-03-21 17:04:15 -04:00
};
2014-09-19 15:54:13 -04:00
Topics.updateTimestamp = function(tid, timestamp, callback) {
async.parallel([
function(next) {
Topics.updateRecent(tid, timestamp, next);
},
function(next) {
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
}
], callback);
2014-09-05 17:39:24 -04:00
};
Topics.updateRecent = function(tid, timestamp, callback) {
callback = callback || function() {};
db.sortedSetAdd('topics:recent', timestamp, tid, callback);
};
2014-03-21 17:04:15 -04:00
};