store group member count in group hash

yet another upgrade script
This commit is contained in:
barisusakli
2015-01-30 22:38:42 -05:00
parent 607e88b3c3
commit dc2a2aa98e
2 changed files with 105 additions and 74 deletions

View File

@@ -21,7 +21,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2015, 0, 21);
latestSchema = Date.UTC(2015, 0, 30);
Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) {
@@ -773,6 +773,41 @@ Upgrade.upgrade = function(callback) {
winston.info('[2015/01/21] Upgrading groups to sorted set skipped');
next();
}
},
function(next) {
thisSchemaDate = Date.UTC(2015, 0, 30);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/01/30] Adding group member counts');
db.getSortedSetRange('groups:createtime', 0, -1, function(err, groupNames) {
if (err) {
return next(err);
}
var now = Date.now();
async.each(groupNames, function(groupName, next) {
db.sortedSetCard('group:' + groupName + ':members', function(err, memberCount) {
console.log(groupName, memberCount);
if (err) {
return next(err);
}
if (parseInt(memberCount, 10)) {
db.setObjectField('group:' + groupName, 'memberCount', memberCount, next);
} else {
next();
}
});
}, function(err) {
winston.info('[2015/01/30] Adding group member counts done');
Upgrade.update(thisSchemaDate, next);
});
});
} else {
winston.info('[2015/01/30] Adding group member counts skipped');
next();
}
}
// Add new schema updates here