mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 17:37:11 +02:00
store group member count in group hash
yet another upgrade script
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user