mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 17:56:16 +01:00
moved posts and recent to new files
This commit is contained in:
36
src/topics/recent.js
Normal file
36
src/topics/recent.js
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
'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);
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user