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", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.22.2", "version": "3.22.3",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

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