Skip to content

Node.js based forum software built for the modern web

topics.getPids will return mainPid as well

barisusaklia69973e7a76e
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index beb7290c1b..a488937dcf 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -36,24 +36,15 @@ module.exports = function(Categories) {
}
updatePostCount(tid, oldCid, cid);
- async.parallel({
- mainPid: function(next) {
- topics.getTopicField(tid, 'mainPid', next);
- },
- pids: function(next) {
- topics.getPids(tid, next);
- }
- }, function(err, results) {
+ topics.getPids(tid, function(err, pids) {
if (err) {
return winston.error(err.message);
}
- if (!results.mainPid && results.pids && !results.pids.length) {
+ if (pids && !pids.length) {
return;
}
- var pids = [results.mainPid].concat(results.pids);
-
var keys = pids.map(function(pid) {
return 'post:' + pid;
});
diff --git a/src/threadTools.js b/src/threadTools.js
index 179c37b263..65bfdd26ae 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -73,7 +73,7 @@ var winston = require('winston'),
ThreadTools.purge = function(tid, uid, callback) {
async.parallel({
topic: function(next) {
- topics.getTopicFields(tid, ['cid', 'mainPid'], next);
+ topics.getTopicFields(tid, ['cid'], next);
},
pids: function(next) {
topics.getPids(tid, next);
@@ -83,16 +83,9 @@ var winston = require('winston'),
return callback(err);
}
- var pids = [];
- if (results.topic.mainPid) {
- pids = [results.topic.mainPid].concat(results.pids);
- } else {
- pids = results.pids;
- }
-
async.parallel([
function(next) {
- async.eachLimit(pids, 10, posts.purge, next);
+ async.eachLimit(results.pids, 10, posts.purge, next);
},
function(next) {
topics.purge(tid, next);
diff --git a/src/topics/posts.js b/src/topics/posts.js
index 593cae4e18..8c755dd393 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -182,7 +182,22 @@ module.exports = function(Topics) {
};
Topics.getPids = function(tid, callback) {
- db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, callback);
+ async.parallel({
+ mainPid: function(next) {
+ Topics.getTopicField(tid, 'mainPid', next);
+ },
+ pids: function(next) {
+ db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, next);
+ }
+ }, function(err, results) {
+ if (err) {
+ return callback(err);
+ }
+ if (results.mainPid) {
+ results.pids = [results.mainPid].concat(results.pids);
+ }
+ callback(null, results.pids);
+ });
};
Topics.increasePostCount = function(tid, callback) {