|
|
@ -32,6 +32,39 @@ module.exports = function(Categories) {
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.updateRecentTid = function(cid, tid, callback) {
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
|
|
|
count: function(next) {
|
|
|
|
|
|
|
|
db.sortedSetCard('cid:' + cid + ':recent_tids', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
numRecentReplies: function(next) {
|
|
|
|
|
|
|
|
db.getObjectField('category:' + cid, 'numRecentReplies', next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (results.count < results.numRecentReplies) {
|
|
|
|
|
|
|
|
return db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid, callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function(next) {
|
|
|
|
|
|
|
|
db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, results.count - results.numRecentReplies, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function(data, next) {
|
|
|
|
|
|
|
|
if (!data.length) {
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
db.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function(next) {
|
|
|
|
|
|
|
|
db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getRecentTopicReplies = function(categoryData, uid, callback) {
|
|
|
|
Categories.getRecentTopicReplies = function(categoryData, uid, callback) {
|
|
|
|
if (!Array.isArray(categoryData) || !categoryData.length) {
|
|
|
|
if (!Array.isArray(categoryData) || !categoryData.length) {
|
|
|
|
return callback();
|
|
|
|
return callback();
|
|
|
@ -39,7 +72,10 @@ module.exports = function(Categories) {
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
async.map(categoryData, getRecentTopicTids, next);
|
|
|
|
var keys = categoryData.map(function(category) {
|
|
|
|
|
|
|
|
return 'cid:' + category.cid + ':recent_tids';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
db.getSortedSetsMembers(keys, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(results, next) {
|
|
|
|
function(results, next) {
|
|
|
|
var tids = _.flatten(results);
|
|
|
|
var tids = _.flatten(results);
|
|
|
@ -62,45 +98,6 @@ module.exports = function(Categories) {
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getRecentTopicTids(category, callback) {
|
|
|
|
|
|
|
|
var count = parseInt(category.numRecentReplies, 10);
|
|
|
|
|
|
|
|
if (!count) {
|
|
|
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count === 1) {
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
db.getSortedSetRevRange('cid:' + category.cid + ':pids', 0, 0, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (pid, next) {
|
|
|
|
|
|
|
|
posts.getPostField(pid, 'tid', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (tid, next) {
|
|
|
|
|
|
|
|
next(null, [tid]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
|
|
|
pinnedTids: function(next) {
|
|
|
|
|
|
|
|
db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, -1, '+inf', Date.now(), next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
tids: function(next) {
|
|
|
|
|
|
|
|
db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, Math.max(1, count), Date.now(), '-inf', next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results.tids = results.tids.concat(results.pinnedTids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, results.tids);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTopics(tids, callback) {
|
|
|
|
function getTopics(tids, callback) {
|
|
|
|
var topicData;
|
|
|
|
var topicData;
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|