mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
speed up category purge
using eachLimit dont emit stats on every topic delete
This commit is contained in:
@@ -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(move
|
||||
if (!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(move
|
||||
getTopicEl(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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user