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