error checks more err first, replaced a eachSeries with async.map

v1.18.x
Baris Soner Usakli 11 years ago
parent 1b5e44a763
commit a8e5c7d149

@ -248,7 +248,10 @@ var fs = require('fs'),
}
if (userData) {
user.getFollowing(userData.uid, function (followingData) {
user.getFollowing(userData.uid, function (err, followingData) {
if(err) {
return next(err);
}
userData.following = followingData;
userData.followingCount = followingData.length;
res.json(userData);
@ -271,7 +274,10 @@ var fs = require('fs'),
}
if (userData) {
user.getFollowers(userData.uid, function (followersData) {
user.getFollowers(userData.uid, function (err, followersData) {
if(err) {
return next(err);
}
userData.followers = followersData;
userData.followersCount = followersData.length;
res.json(userData);
@ -634,12 +640,13 @@ var fs = require('fs'),
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
user.getFollowingCount(userData.uid, function (followingCount) {
user.getFollowerCount(userData.uid, function (followerCount) {
userData.followingCount = followingCount;
userData.followerCount = followerCount;
callback(null, userData);
});
user.getFollowStats(userData.uid, function (err, followStats) {
if(err) {
return callback(err);
}
userData.followingCount = followStats.followingCount;
userData.followerCount = followStats.followerCount;
callback(null, userData);
});
});
}

@ -548,7 +548,7 @@ var bcrypt = require('bcryptjs'),
return usernamesHash[username];
});
User.getDataForUsers(results, function(userdata) {
User.getDataForUsers(results, function(err, userdata) {
var diff = process.hrtime(start);
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
callback(null, {timing: timing, users: userdata});
@ -610,73 +610,76 @@ var bcrypt = require('bcryptjs'),
User.getFollowing = function(uid, callback) {
db.getSetMembers('following:' + uid, function(err, userIds) {
if (!err) {
User.getDataForUsers(userIds, callback);
} else {
console.log(err);
if(err) {
return callback(err);
}
User.getDataForUsers(userIds, callback);
});
};
User.getFollowers = function(uid, callback) {
db.getSetMembers('followers:' + uid, function(err, userIds) {
if (!err) {
User.getDataForUsers(userIds, callback);
} else {
console.log(err);
if(err) {
return callback(err);
}
User.getDataForUsers(userIds, callback);
});
};
User.getFollowingCount = function(uid, callback) {
db.getSetMembers('following:' + uid, function(err, userIds) {
if (err) {
console.log(err);
} else {
userIds = userIds.filter(function(value) {
return parseInt(value, 10) !== 0;
});
callback(userIds.length);
return callback(err);
}
userIds = userIds.filter(function(value) {
return parseInt(value, 10) !== 0;
});
callback(null, userIds.length);
});
};
User.getFollowerCount = function(uid, callback) {
db.getSetMembers('followers:' + uid, function(err, userIds) {
if(err) {
console.log(err);
} else {
userIds = userIds.filter(function(value) {
return parseInt(value, 10) !== 0;
});
callback(userIds.length);
return callback(err);
}
userIds = userIds.filter(function(value) {
return parseInt(value, 10) !== 0;
});
callback(null, userIds.length);
});
};
User.getFollowStats = function (uid, callback) {
async.parallel({
followingCount: function(next) {
User.getFollowingCount(uid, next);
},
followerCount : function(next) {
User.getFollowerCount(uid, next);
}
}, callback);
}
User.getDataForUsers = function(uids, callback) {
var returnData = [];
if (!uids || !Array.isArray(uids) || uids.length === 0) {
callback(returnData);
return;
return callback(null, []);
}
function iterator(uid, callback) {
function getUserData(uid, next) {
if(parseInt(uid, 10) === 0) {
return callback(null);
return next(null, null);
}
User.getUserData(uid, function(err, userData) {
returnData.push(userData);
callback(null);
});
User.getUserData(uid, next);
}
async.eachSeries(uids, iterator, function(err) {
callback(returnData);
});
async.map(uids, getUserData, callback);
};
User.sendPostNotificationToFollowers = function(uid, tid, pid) {

Loading…
Cancel
Save