optimize getUserGroups to work with multiple user ids

v1.18.x
barisusakli 11 years ago
parent 5b681678b1
commit b8279dc737

@ -438,7 +438,7 @@
});
};
Groups.getUserGroups = function(uid, callback) {
Groups.getUserGroups = function(uids, callback) {
var ignoredGroups = ['registered-users'];
db.getSetMembers('groups', function(err, groupNames) {
@ -466,19 +466,22 @@
return 'group:' + group.name + ':members';
});
db.isMemberOfSets(groupSets, uid, function(err, isMembers) {
if (err) {
return callback(err);
}
for(var i=isMembers.length - 1; i>=0; --i) {
if (!isMembers[i]) {
groupData.splice(i, 1);
async.map(uids, function(uid, next) {
db.isMemberOfSets(groupSets, uid, function(err, isMembers) {
if (err) {
return next(err);
}
}
callback(null, groupData);
});
var memberOf = [];
isMembers.forEach(function(isMember, index) {
if (isMember) {
memberOf.push(groupData[index]);
}
});
next(null, memberOf);
});
}, callback);
});
});
};

@ -222,21 +222,31 @@ var async = require('async'),
};
Posts.getUserInfoForPosts = function(uids, callback) {
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
async.parallel({
groups: function(next) {
groups.getUserGroups(uids, next);
},
userData: function(next) {
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
var userData = results.userData;
for(var i=0; i<userData.length; ++i) {
userData[i].groups = results.groups[i];
}
async.map(userData, function(userData, next) {
var userInfo = {
uid: userData.uid || 0,
username: userData.username || '[[global:guest]]',
userslug: userData.userslug || '',
reputation: userData.reputation || 0,
postcount: userData.postcount || 0,
banned: parseInt(userData.banned, 10) === 1,
picture: userData.picture || user.createGravatarURLFromEmail('')
};
userData.uid = userData.uid || 0;
userData.username = userData.username || '[[global:guest]]';
userData.userslug = userData.userslug || '';
userData.reputation = userData.reputation || 0;
userData.postcount = userData.postcount || 0;
userData.banned = parseInt(userData.banned, 10) === 1;
userData.picture = userData.picture || user.createGravatarURLFromEmail('');
async.parallel({
signature: function(next) {
@ -247,18 +257,14 @@ var async = require('async'),
},
customProfileInfo: function(next) {
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
},
groups: function(next) {
groups.getUserGroups(userData.uid, next);
}
}, function(err, results) {
if (err) {
return next(err);
}
userInfo.signature = results.signature;
userInfo.custom_profile_info = results.customProfileInfo.profile;
userInfo.groups = results.groups;
next(null, userInfo);
userData.signature = results.signature;
userData.custom_profile_info = results.customProfileInfo.profile;
next(null, userData);
});
}, callback);
});

Loading…
Cancel
Save