mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: optimize group rename
removed async.each
This commit is contained in:
@@ -225,9 +225,8 @@ module.exports = function (Groups) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
async.each(groups, function (group, next) {
|
||||
renameGroupMember('group:' + group + ':members', oldName, newName, next);
|
||||
}, next);
|
||||
const keys = groups.map(group => 'group:' + group + ':members');
|
||||
renameGroupsMember(keys, oldName, newName, next);
|
||||
});
|
||||
},
|
||||
async.apply(db.rename, 'group:' + oldName, 'group:' + newName),
|
||||
@@ -237,10 +236,8 @@ module.exports = function (Groups) {
|
||||
async.apply(db.rename, 'group:' + oldName + ':invited', 'group:' + newName + ':invited'),
|
||||
async.apply(db.rename, 'group:' + oldName + ':member:pids', 'group:' + newName + ':member:pids'),
|
||||
|
||||
async.apply(renameGroupMember, 'groups:createtime', oldName, newName),
|
||||
async.apply(renameGroupMember, 'groups:visible:createtime', oldName, newName),
|
||||
async.apply(renameGroupMember, 'groups:visible:memberCount', oldName, newName),
|
||||
async.apply(renameGroupMember, 'groups:visible:name', oldName.toLowerCase() + ':' + oldName, newName.toLowerCase() + ':' + newName),
|
||||
async.apply(renameGroupsMember, ['groups:createtime', 'groups:visible:createtime', 'groups:visible:memberCount'], oldName, newName),
|
||||
async.apply(renameGroupsMember, ['groups:visible:name'], oldName.toLowerCase() + ':' + oldName, newName.toLowerCase() + ':' + newName),
|
||||
function (next) {
|
||||
plugins.fireHook('action:group.rename', {
|
||||
old: oldName,
|
||||
@@ -274,25 +271,25 @@ module.exports = function (Groups) {
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function renameGroupMember(group, oldName, newName, callback) {
|
||||
var score;
|
||||
function renameGroupsMember(keys, oldName, newName, callback) {
|
||||
var scores;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.isSortedSetMember(group, oldName, next);
|
||||
db.isMemberOfSortedSets(keys, oldName, next);
|
||||
},
|
||||
function (isMember, next) {
|
||||
if (!isMember) {
|
||||
function (isMembers, next) {
|
||||
keys = keys.filter((key, index) => isMembers[index]);
|
||||
if (!keys.length) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
db.sortedSetScore(group, oldName, next);
|
||||
db.sortedSetsScore(keys, oldName, next);
|
||||
},
|
||||
function (_score, next) {
|
||||
score = _score;
|
||||
db.sortedSetRemove(group, oldName, next);
|
||||
function (_scores, next) {
|
||||
scores = _scores;
|
||||
db.sortedSetsRemove(keys, oldName, next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd(group, score, newName, next);
|
||||
db.sortedSetsAdd(keys, scores, newName, next);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user