fixed categories.getRecentReplies so it only returns count posts instead of getting 10, posts are added and removed from sorted set when they are deleted restored

v1.18.x
Baris Usakli 11 years ago
parent 9816272b7b
commit 401a30e02c

@ -216,24 +216,22 @@ var db = require('./database.js'),
};
Categories.getRecentReplies = function(cid, count, callback) {
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, (count < 10) ? 10 : count, function(err, pids) {
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
if (err) {
winston.err(err);
callback([]);
return;
return callback([]);
}
if (pids.length === 0) {
callback([]);
return;
return callback([]);
}
posts.getPostSummaryByPids(pids, true, function(err, postData) {
if (postData.length > count) {
postData = postData.slice(0, count);
if(err) {
return callback(err);
}
callback(postData);
callback(null, postData);
});
});
};

@ -143,6 +143,12 @@ var db = require('./database'),
db.sortedSetAdd('users:postcount', postcount, postData.uid);
});
topics.getTopicField(postData.tid, 'cid', function(err, cid) {
if(!err) {
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid);
}
});
// Delete the thread if it is the last undeleted post
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
if (err && err.message === 'no-undeleted-pids-found') {
@ -192,6 +198,12 @@ var db = require('./database'),
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
topics.updateTimestamp(postData.tid, timestamp);
topics.getTopicField(postData.tid, 'cid', function(err, cid) {
if(!err) {
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);
}
});
});
});

@ -39,22 +39,29 @@ var path = require('path'),
res.json(200, config);
});
app.get('/home', function (req, res) {
app.get('/home', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
categories.getAllCategories(uid, function (err, data) {
data.categories = data.categories.filter(function (category) {
return (!category.disabled || parseInt(category.disabled, 10) === 0);
});
function iterator(category, callback) {
categories.getRecentReplies(category.cid, 2, function (posts) {
function getRecentReplies(category, callback) {
categories.getRecentReplies(category.cid, 2, function (err, posts) {
if(err) {
return callback(err);
}
category.posts = posts;
category.post_count = posts.length > 2 ? 2 : posts.length;
callback(null);
});
}
async.each(data.categories, iterator, function (err) {
async.each(data.categories, getRecentReplies, function (err) {
if(err) {
return next(err);
}
data.motd_class = (parseInt(meta.config.show_motd, 10) === 1 || meta.config.show_motd === undefined) ? '' : ' none';
data.motd_class += (meta.config.motd && meta.config.motd.length > 0 ? '' : ' default');

@ -672,7 +672,7 @@ websockets.init = function(io) {
});
socket.on('api:categories.getRecentReplies', function(tid) {
categories.getRecentReplies(tid, 4, function(replies) {
categories.getRecentReplies(tid, 4, function(err, replies) {
socket.emit('api:categories.getRecentReplies', replies);
});
});

Loading…
Cancel
Save