You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
743 B
JavaScript
37 lines
743 B
JavaScript
11 years ago
|
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
var db = require('./../database');
|
||
|
|
||
|
module.exports = function(Topics) {
|
||
|
|
||
|
Topics.getLatestTopics = function(uid, start, end, term, callback) {
|
||
|
Topics.getLatestTids(start, end, term, function(err, tids) {
|
||
|
if(err) {
|
||
|
return callback(err);
|
||
|
}
|
||
|
|
||
|
Topics.getTopics('topics:recent', uid, tids, callback);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
Topics.getLatestTids = function(start, end, term, callback) {
|
||
|
var terms = {
|
||
|
day: 86400000,
|
||
|
week: 604800000,
|
||
|
month: 2592000000
|
||
|
};
|
||
|
|
||
|
var since = terms.day;
|
||
|
if(terms[term]) {
|
||
|
since = terms[term];
|
||
|
}
|
||
|
|
||
|
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
|
||
|
|
||
|
db.getSortedSetRevRangeByScore(['topics:recent', '+inf', Date.now() - since, 'LIMIT', start, count], callback);
|
||
|
};
|
||
|
|
||
|
};
|