Node.js based forum software built for the modern web
speed up category purge
barisusaklia4d4e53f45ab
diff --git a/public/src/forum/categoryTools.js b/public/src/forum/categoryTools.jsindex cc4044aba9..dc66fe02f6 100644--- a/public/src/forum/categoryTools.js+++ b/public/src/forum/categoryTools.js@@ -1,7 +1,7 @@'use strict';-/* globals define, app, translator, socket, bootbox */+/* globals define, app, translator, socket, bootbox, ajaxify */define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move, topicSelect) {@@ -28,7 +28,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move$('.lock_thread').on('click', function() {var tids = topicSelect.getSelectedTids();if (tids.length) {- socket.emit(isAny(isTopicLocked, tids) ? 'topics.unlock' : 'topics.lock', tids, onCommandComplete);+ socket.emit(isAny(isTopicLocked, tids) ? 'topics.unlock' : 'topics.lock', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);}return false;});@@ -36,7 +36,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move$('.pin_thread').on('click', function() {var tids = topicSelect.getSelectedTids();if (tids.length) {- socket.emit(isAny(isTopicPinned, tids) ? 'topics.unpin' : 'topics.pin', tids, onCommandComplete);+ socket.emit(isAny(isTopicPinned, tids) ? 'topics.unpin' : 'topics.pin', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);}return false;});@@ -93,7 +93,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(moveif (!confirm) {return;}- socket.emit('topics.' + command, tids, onCommandComplete);++ socket.emit('topics.' + command, {tids: tids, cid: CategoryTools.cid}, onCommandComplete);});});}@@ -200,8 +201,13 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(movegetTopicEl(data.tid).remove();}- function onTopicPurged(tid) {- getTopicEl(tid).remove();+ function onTopicPurged(tids) {+ if (!tids) {+ return;+ }+ for(var i=0; i<tids.length; ++i) {+ getTopicEl(tids[i]).remove();+ }}return CategoryTools;diff --git a/public/src/forum/topic/events.js b/public/src/forum/topic/events.jsindex e0617e8932..db22ef4c5a 100644--- a/public/src/forum/topic/events.js+++ b/public/src/forum/topic/events.js@@ -74,8 +74,8 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', 'threadTools.setDeleteState(data);}- function onTopicPurged(tid, cid) {- ajaxify.go('category/' + cid);+ function onTopicPurged(tid) {+ ajaxify.go('category/' + ajaxify.variables.get('category_id'));}function toggleTopicLockedState(data) {diff --git a/src/categories/delete.js b/src/categories/delete.jsindex 8c4c0520f8..1783ae77b1 100644--- a/src/categories/delete.js+++ b/src/categories/delete.js@@ -14,7 +14,7 @@ module.exports = function(Categories) {return callback(err);}- async.each(tids, function(tid, next) {+ async.eachLimit(tids, 10, function(tid, next) {threadTools.purge(tid, 0, next);}, function(err) {if (err) {diff --git a/src/posts/delete.js b/src/posts/delete.jsindex 664d0b4fea..ff0db517e5 100644--- a/src/posts/delete.js+++ b/src/posts/delete.js@@ -133,6 +133,12 @@ module.exports = function(Posts) {async.each(results.downvoters, function(uid, next) {db.sortedSetRemove('uid:' + uid + ':downvote', pid, next);}, next);+ },+ function(next) {+ db.delete('pid:' + pid + ':upvote', next);+ },+ function(next) {+ db.delete('pid:' + pid + ':downvote', next);}], callback);});diff --git a/src/socket.io/topics.js b/src/socket.io/topics.jsindex 732757d62f..d5d452b5b6 100644--- a/src/socket.io/topics.js+++ b/src/socket.io/topics.js@@ -59,7 +59,7 @@ SocketTopics.postcount = function(socket, tid, callback) {SocketTopics.increaseViewCount = function(socket, tid) {topics.increaseViewCount(tid);-}+};SocketTopics.markAsRead = function(socket, tid) {if(!tid || !socket.uid) {@@ -152,40 +152,50 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {}, callback);};-SocketTopics.delete = function(socket, tids, callback) {- doTopicAction('delete', socket, tids, callback);+SocketTopics.delete = function(socket, data, callback) {+ doTopicAction('delete', socket, data, callback);};-SocketTopics.restore = function(socket, tids, callback) {- doTopicAction('restore', socket, tids, callback);+SocketTopics.restore = function(socket, data, callback) {+ doTopicAction('restore', socket, data, callback);};-SocketTopics.purge = function(socket, tids, callback) {- doTopicAction('purge', socket, tids, callback);+SocketTopics.purge = function(socket, data, callback) {+ doTopicAction('purge', socket, data, function(err) {+ if (err) {+ return callback(err);+ }+ websockets.emitTopicPostStats();+ websockets.in('category_' + data.cid).emit('event:topic_purged', data.tids);+ async.each(data.tids, function(tid, next) {+ websockets.in('topic_' + tid).emit('event:topic_purged', tid);+ next();+ }, callback);+ });};-SocketTopics.lock = function(socket, tids, callback) {- doTopicAction('lock', socket, tids, callback);+SocketTopics.lock = function(socket, data, callback) {+ doTopicAction('lock', socket, data, callback);};-SocketTopics.unlock = function(socket, tids, callback) {- doTopicAction('unlock', socket, tids, callback);+SocketTopics.unlock = function(socket, data, callback) {+ doTopicAction('unlock', socket, data, callback);};-SocketTopics.pin = function(socket, tids, callback) {- doTopicAction('pin', socket, tids, callback);+SocketTopics.pin = function(socket, data, callback) {+ doTopicAction('pin', socket, data, callback);};-SocketTopics.unpin = function(socket, tids, callback) {- doTopicAction('unpin', socket, tids, callback);+SocketTopics.unpin = function(socket, data, callback) {+ doTopicAction('unpin', socket, data, callback);};-function doTopicAction(action, socket, tids, callback) {- if(!tids) {+function doTopicAction(action, socket, data, callback) {+ if(!data || !Array.isArray(data.tids) || !data.cid) {return callback(new Error('[[error:invalid-tid]]'));}- async.each(tids, function(tid, next) {+ async.each(data.tids, function(tid, next) {privileges.topics.canEdit(tid, socket.uid, function(err, canEdit) {if(err) {return next(err);diff --git a/src/threadTools.js b/src/threadTools.jsindex 385407e481..179c37b263 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -86,25 +86,18 @@ var winston = require('winston'),var pids = [];if (results.topic.mainPid) {pids = [results.topic.mainPid].concat(results.pids);+ } else {+ pids = results.pids;}async.parallel([function(next) {- async.each(pids, posts.purge, next);+ async.eachLimit(pids, 10, posts.purge, next);},function(next) {topics.purge(tid, next);}- ], function(err) {- if (err) {- return callback(err);- }-- websockets.emitTopicPostStats();- websockets.in('topic_' + tid).emit('event:topic_purged', tid, results.topic.cid);- websockets.in('category_' + results.topic.cid).emit('event:topic_purged', tid);- callback();- });+ ], callback);});};