Merge getGlobalRank and getProfile into one query

Really the entire "Account" thing needs to be refactored/deleted and
replaced with separate global account and per-channel state, which I
plan to do, but this brings some minor benefit in the meantime
This commit is contained in:
Calvin Montgomery 2016-09-26 22:36:17 -07:00
parent e1120455b2
commit c88c63a422
2 changed files with 8 additions and 14 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.22.2",
"version": "3.22.3",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -42,14 +42,15 @@ module.exports.getAccount = function (name, ip, opts, cb) {
.then(function (aliases) {
data.aliases = aliases;
if (name && opts.registered) {
return Q.nfcall(db.users.getGlobalRank, name);
return Q.nfcall(db.users.getUser, name);
} else if (name) {
return 0;
return { global_rank: 0, profile: { text: "", image: "" } };
} else {
return -1;
return { global_rank: -1, profile: { text: "", image: "" } };
}
}).then(function (globalRank) {
data.globalRank = globalRank;
}).then(function (user) {
data.globalRank = user.global_rank;
data.profile = user.profile;
if (opts.channel && opts.registered) {
return Q.nfcall(db.channels.getRank, opts.channel, name);
} else {
@ -63,13 +64,6 @@ module.exports.getAccount = function (name, ip, opts, cb) {
}
}).then(function (chanRank) {
data.channelRank = chanRank;
/* Look up profile for registered user */
if (data.globalRank >= 1) {
return Q.nfcall(db.users.getProfile, name);
} else {
return { text: "", image: "" };
}
}).then(function (profile) {
setImmediate(function () {
cb(null, new Account({
name: name,
@ -77,7 +71,7 @@ module.exports.getAccount = function (name, ip, opts, cb) {
aliases: data.aliases,
globalRank: data.globalRank,
channelRank: data.channelRank,
profile: profile
profile: data.profile
}));
});
}).catch(function (err) {