groups pruning method

This commit is contained in:
Julian Lam
2013-11-28 12:55:05 -05:00
parent 56b618c915
commit e3e1a556cd
2 changed files with 31 additions and 7 deletions

View File

@@ -13,8 +13,10 @@
expand: options.expand
}, next);
}, function (err, groups) {
// Remove deleted and hidden groups from this list
callback(err, groups.filter(function (group) {
if (group.deleted === '1') {
console.log(group);
if (group.deleted === '1' || group.hidden === '1') {
return false;
} else {
return true;
@@ -219,5 +221,33 @@
}
});
};
Groups.prune = function(callback) {
// Actually deletes groups (with the deleted flag) from the redis database
RDB.hvals('group:gid', function (err, gids) {
var multi = RDB.multi(),
groupsDeleted = 0;
async.each(gids, function(gid, next) {
Groups.get(gid, {}, function(err, groupObj) {
if (!err && groupObj.deleted === '1') {
multi.hdel('group:gid', groupObj.name);
multi.del('gid:' + gid);
groupsDeleted++;
}
next(null);
});
}, function(err) {
multi.exec(function(err) {
if (!err && process.env.NODE_ENV === 'development') {
winston.info('[groups.prune] Pruned ' + groupsDeleted + ' deleted groups from Redis');
}
callback(err);
});
});
});
};
}(module.exports));