mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
simplified getAllTopics
This commit is contained in:
@@ -424,12 +424,12 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
function getTopics(set, uid, tids, callback) {
|
||||
var latestTopics = {
|
||||
var returnTopics = {
|
||||
'topics': []
|
||||
};
|
||||
|
||||
if (!tids || !tids.length) {
|
||||
return callback(null, latestTopics);
|
||||
return callback(null, returnTopics);
|
||||
}
|
||||
|
||||
async.filter(tids, function(tid, next) {
|
||||
@@ -443,7 +443,7 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
if(!topicData || !topicData.length) {
|
||||
return callback(null, latestTopics);
|
||||
return callback(null, returnTopics);
|
||||
}
|
||||
|
||||
db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) {
|
||||
@@ -451,9 +451,9 @@ var async = require('async'),
|
||||
return calllback(err);
|
||||
}
|
||||
|
||||
latestTopics.nextStart = parseInt(rank, 10) + 1;
|
||||
latestTopics.topics = topicData;
|
||||
callback(null, latestTopics);
|
||||
returnTopics.nextStart = parseInt(rank, 10) + 1;
|
||||
returnTopics.topics = topicData;
|
||||
callback(null, returnTopics);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -905,49 +905,11 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Topics.getAllTopics = function(limit, after, callback) {
|
||||
db.getSetMembers('topics:tid', function(err, tids) {
|
||||
if(err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
var topics = [],
|
||||
numTids, x;
|
||||
|
||||
// Sort into ascending order
|
||||
tids.sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
|
||||
// Eliminate everything after the "after" tid
|
||||
if (after) {
|
||||
for (x = 0, numTids = tids.length; x < numTids; x++) {
|
||||
if (tids[x] >= after) {
|
||||
tids = tids.slice(0, x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (limit) {
|
||||
if (limit > 0 && limit < tids.length) {
|
||||
tids = tids.slice(tids.length - limit);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort into descending order
|
||||
tids.sort(function(a, b) {
|
||||
return b - a;
|
||||
});
|
||||
|
||||
async.each(tids, function(tid, next) {
|
||||
Topics.getTopicDataWithUser(tid, function(err, topicData) {
|
||||
topics.push(topicData);
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
callback(err, topics);
|
||||
});
|
||||
Topics.getAllTopics = function(start, end, callback) {
|
||||
db.getSortedSetRevRange('topics:recent', start, end, function(err, tids) {
|
||||
async.map(tids, function(tid, next) {
|
||||
Topics.getTopicDataWithUser(tid, next);
|
||||
}, callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user