fix ban upgrade closes #2239

v1.18.x
barisusakli 10 years ago
parent 0772e8c41f
commit 26cfe4a3c3

@ -1044,45 +1044,41 @@ Upgrade.upgrade = function(callback) {
} }
}, },
function(next) { function(next) {
thisSchemaDate = Date.UTC(2014, 9, 3); thisSchemaDate = Date.UTC(2014, 9, 7);
if (schemaDate < thisSchemaDate) { if (schemaDate < thisSchemaDate) {
winston.info('[2014/10/3] Banned users sorted set'); winston.info('[2014/10/7] Banned users sorted set');
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) { db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
if (err) { if (err) {
return next(err); return next(err);
} }
var now = Date.now();
async.eachLimit(uids, 50, function(uid, next) { async.eachLimit(uids, 50, function(uid, next) {
User.getMultipleUserFields(uids, ['uid', 'banned'], function(err, userData) { User.getUserField(uid, 'banned', function(err, banned) {
if (err) { if (err) {
return next(err); return next(err);
} }
var bannedUids = userData.filter(function(user) { if (parseInt(banned, 10) !== 1) {
return user && parseInt(user.banned, 10) === 1; return next();
}).map(function(user) { }
return user.uid;
}); db.sortedSetAdd('users:banned', now, uid, next);
var timestamps = [];
var now = Date.now();
bannedUids.forEach(function() {
timestamps.push(now);
});
db.sortedSetAdd('users:banned', timestamps, bannedUids, next);
}); });
}, function(err) { }, function(err) {
if (err) { if (err) {
winston.error('[2014/10/3] Error encountered while updating banned users sorted set'); winston.error('[2014/10/7] Error encountered while updating banned users sorted set');
return next(err); return next(err);
} }
winston.info('[2014/10/3] Banned users added to sorted set'); winston.info('[2014/10/7] Banned users added to sorted set');
Upgrade.update(thisSchemaDate, next); Upgrade.update(thisSchemaDate, next);
}); });
}); });
} else { } else {
winston.info('[2014/10/3] Banned users sorted set skipped'); winston.info('[2014/10/7] Banned users sorted set skipped');
next(); next();
} }
} }

Loading…
Cancel
Save