v1.18.x
barisusakli 10 years ago
parent 8c2fdcc77c
commit 8af64ba984

@ -4,15 +4,14 @@ var async = require('async'),
db = require('../database'), db = require('../database'),
batch = require('../batch'), batch = require('../batch'),
plugins = require('../plugins'), plugins = require('../plugins'),
threadTools = require('../threadTools'); topics = require('../topics');
module.exports = function(Categories) { module.exports = function(Categories) {
Categories.purge = function(cid, callback) { Categories.purge = function(cid, callback) {
batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) { batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) {
async.eachLimit(tids, 10, function(tid, next) { async.eachLimit(tids, 10, function(tid, next) {
threadTools.purge(tid, 0, next); topics.purgePostsAndTopic(tid, next);
}, next); }, next);
}, {alwaysStartAt: 0}, function(err) { }, {alwaysStartAt: 0}, function(err) {
if (err) { if (err) {

@ -91,9 +91,6 @@ categoriesController.get = function(req, res, callback) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
async.parallel({ async.parallel({
exists: function(next) {
categories.exists(cid, next);
},
categoryData: function(next) { categoryData: function(next) {
categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next); categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next);
}, },
@ -108,7 +105,7 @@ categoriesController.get = function(req, res, callback) {
function(results, next) { function(results, next) {
userPrivileges = results.privileges; userPrivileges = results.privileges;
if (!results.exists || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) { if (!results.categoryData.slug || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) {
return callback(); return callback();
} }

@ -40,6 +40,11 @@ topicsController.get = function(req, res, callback) {
}, next); }, next);
}, },
function (results, next) { function (results, next) {
if (!results.topic.slug) {
return callback();
}
userPrivileges = results.privileges; userPrivileges = results.privileges;
if (!userPrivileges.read || (parseInt(results.topic.deleted, 10) && !userPrivileges.view_deleted)) { if (!userPrivileges.read || (parseInt(results.topic.deleted, 10) && !userPrivileges.view_deleted)) {

@ -66,7 +66,7 @@ var async = require('async'),
} }
ThreadTools.purge = function(tid, uid, callback) { ThreadTools.purge = function(tid, uid, callback) {
var topic; var cid;
async.waterfall([ async.waterfall([
function(next) { function(next) {
topics.exists(tid, next); topics.exists(tid, next);
@ -82,23 +82,15 @@ var async = require('async'),
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
topics.getTopicFields(tid, ['mainPid', 'cid'], next); topics.getTopicField(tid, 'cid', next);
}, },
function (_topic, next) { function (_cid, next) {
topic = _topic; cid = _cid;
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) { topics.purgePostsAndTopic(tid, next);
async.eachLimit(pids, 10, posts.purge, next);
}, {alwaysStartAt: 0}, next);
},
function (next) {
posts.purge(topic.mainPid, next);
},
function (next) {
topics.purge(tid, next);
}, },
function (next) { function (next) {
next(null, {tid: tid, cid: topic.cid, uid: uid}); next(null, {tid: tid, cid: cid, uid: uid});
} }
], callback); ], callback);
}; };

@ -5,7 +5,8 @@ var async = require('async'),
user = require('../user'), user = require('../user'),
posts = require('../posts'), posts = require('../posts'),
plugins = require('../plugins'); plugins = require('../plugins'),
batch = require('../batch');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -80,6 +81,27 @@ module.exports = function(Topics) {
}); });
}; };
Topics.purgePostsAndTopic = function(tid, callback) {
var mainPid;
async.waterfall([
function (next) {
Topics.getTopicField(tid, 'mainPid', next);
},
function (_mainPid, next) {
mainPid = _mainPid;
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
async.eachLimit(pids, 10, posts.purge, next);
}, {alwaysStartAt: 0}, next);
},
function (next) {
posts.purge(mainPid, next);
},
function (next) {
Topics.purge(tid, next);
}
], callback);
};
Topics.purge = function(tid, callback) { Topics.purge = function(tid, callback) {
async.parallel([ async.parallel([
function(next) { function(next) {

Loading…
Cancel
Save