small tweak

v1.18.x
barisusakli 11 years ago
parent 5c91bc4335
commit 60624eedec

@ -25,9 +25,7 @@ module.exports = function(Categories) {
}; };
Categories.getRecentTopicReplies = function(categoryData, callback) { Categories.getRecentTopicReplies = function(categoryData, callback) {
async.map(categoryData, function(category, next) { async.map(categoryData, getRecentTopicPids, function(err, results) {
getRecentTopicPids(category.cid, parseInt(category.numRecentReplies), next);
}, function(err, results) {
var pids = _.flatten(results); var pids = _.flatten(results);
pids = pids.filter(function(pid, index, array) { pids = pids.filter(function(pid, index, array) {
@ -56,13 +54,13 @@ module.exports = function(Categories) {
next(); next();
} }
function getRecentTopicPids(cid, count, callback) { function getRecentTopicPids(category, callback) {
count = parseInt(count, 10); var count = parseInt(category.numRecentReplies, 10);
if (!count) { if (!count) {
return callback(null, []); return callback(null, []);
} }
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 0, function(err, pids) { db.getSortedSetRevRange('categories:recent_posts:cid:' + category.cid, 0, 0, function(err, pids) {
if (err || !Array.isArray(pids) || !pids.length) { if (err || !Array.isArray(pids) || !pids.length) {
return callback(err, []); return callback(err, []);
} }
@ -73,10 +71,10 @@ module.exports = function(Categories) {
async.parallel({ async.parallel({
pinnedTids: function(next) { pinnedTids: function(next) {
db.getSortedSetRevRangeByScore('categories:' + cid + ':tid', 0, -1, Infinity, Date.now(), next); db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, -1, Infinity, Date.now(), next);
}, },
tids: function(next) { tids: function(next) {
db.getSortedSetRevRangeByScore('categories:' + cid + ':tid', 0, Math.max(0, count), Date.now(), 0, next); db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, Math.max(0, count), Date.now(), 0, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {

Loading…
Cancel
Save