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';
|
'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) {
|
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() {
|
$('.lock_thread').on('click', function() {
|
||||||
var tids = topicSelect.getSelectedTids();
|
var tids = topicSelect.getSelectedTids();
|
||||||
if (tids.length) {
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -36,7 +36,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
|
|||||||
$('.pin_thread').on('click', function() {
|
$('.pin_thread').on('click', function() {
|
||||||
var tids = topicSelect.getSelectedTids();
|
var tids = topicSelect.getSelectedTids();
|
||||||
if (tids.length) {
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -93,7 +93,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
|
|||||||
if (!confirm) {
|
if (!confirm) {
|
||||||
return;
|
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();
|
getTopicEl(data.tid).remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTopicPurged(tid) {
|
function onTopicPurged(tids) {
|
||||||
getTopicEl(tid).remove();
|
if (!tids) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i=0; i<tids.length; ++i) {
|
||||||
|
getTopicEl(tids[i]).remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CategoryTools;
|
return CategoryTools;
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
threadTools.setDeleteState(data);
|
threadTools.setDeleteState(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTopicPurged(tid, cid) {
|
function onTopicPurged(tid) {
|
||||||
ajaxify.go('category/' + cid);
|
ajaxify.go('category/' + ajaxify.variables.get('category_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTopicLockedState(data) {
|
function toggleTopicLockedState(data) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ module.exports = function(Categories) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(tids, function(tid, next) {
|
async.eachLimit(tids, 10, function(tid, next) {
|
||||||
threadTools.purge(tid, 0, next);
|
threadTools.purge(tid, 0, next);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -133,6 +133,12 @@ module.exports = function(Posts) {
|
|||||||
async.each(results.downvoters, function(uid, next) {
|
async.each(results.downvoters, function(uid, next) {
|
||||||
db.sortedSetRemove('uid:' + uid + ':downvote', pid, next);
|
db.sortedSetRemove('uid:' + uid + ':downvote', pid, next);
|
||||||
}, next);
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.delete('pid:' + pid + ':upvote', next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.delete('pid:' + pid + ':downvote', next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ SocketTopics.postcount = function(socket, tid, callback) {
|
|||||||
|
|
||||||
SocketTopics.increaseViewCount = function(socket, tid) {
|
SocketTopics.increaseViewCount = function(socket, tid) {
|
||||||
topics.increaseViewCount(tid);
|
topics.increaseViewCount(tid);
|
||||||
}
|
};
|
||||||
|
|
||||||
SocketTopics.markAsRead = function(socket, tid) {
|
SocketTopics.markAsRead = function(socket, tid) {
|
||||||
if(!tid || !socket.uid) {
|
if(!tid || !socket.uid) {
|
||||||
@@ -152,40 +152,50 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {
|
|||||||
}, callback);
|
}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.delete = function(socket, tids, callback) {
|
SocketTopics.delete = function(socket, data, callback) {
|
||||||
doTopicAction('delete', socket, tids, callback);
|
doTopicAction('delete', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.restore = function(socket, tids, callback) {
|
SocketTopics.restore = function(socket, data, callback) {
|
||||||
doTopicAction('restore', socket, tids, callback);
|
doTopicAction('restore', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.purge = function(socket, tids, callback) {
|
SocketTopics.purge = function(socket, data, callback) {
|
||||||
doTopicAction('purge', socket, tids, 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) {
|
SocketTopics.lock = function(socket, data, callback) {
|
||||||
doTopicAction('lock', socket, tids, callback);
|
doTopicAction('lock', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.unlock = function(socket, tids, callback) {
|
SocketTopics.unlock = function(socket, data, callback) {
|
||||||
doTopicAction('unlock', socket, tids, callback);
|
doTopicAction('unlock', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.pin = function(socket, tids, callback) {
|
SocketTopics.pin = function(socket, data, callback) {
|
||||||
doTopicAction('pin', socket, tids, callback);
|
doTopicAction('pin', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.unpin = function(socket, tids, callback) {
|
SocketTopics.unpin = function(socket, data, callback) {
|
||||||
doTopicAction('unpin', socket, tids, callback);
|
doTopicAction('unpin', socket, data, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function doTopicAction(action, socket, tids, callback) {
|
function doTopicAction(action, socket, data, callback) {
|
||||||
if(!tids) {
|
if(!data || !Array.isArray(data.tids) || !data.cid) {
|
||||||
return callback(new Error('[[error:invalid-tid]]'));
|
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) {
|
privileges.topics.canEdit(tid, socket.uid, function(err, canEdit) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|||||||
@@ -86,25 +86,18 @@ var winston = require('winston'),
|
|||||||
var pids = [];
|
var pids = [];
|
||||||
if (results.topic.mainPid) {
|
if (results.topic.mainPid) {
|
||||||
pids = [results.topic.mainPid].concat(results.pids);
|
pids = [results.topic.mainPid].concat(results.pids);
|
||||||
|
} else {
|
||||||
|
pids = results.pids;
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
async.each(pids, posts.purge, next);
|
async.eachLimit(pids, 10, posts.purge, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
topics.purge(tid, next);
|
topics.purge(tid, next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], callback);
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user