From c88c63a422eb68a27fe83ab1926ae3df1fb70827 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 26 Sep 2016 22:36:17 -0700 Subject: [PATCH] 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 --- package.json | 2 +- src/account.js | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1b5a8d5c..638be586 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/account.js b/src/account.js index 0d9e01f6..d8e7d1ca 100644 --- a/src/account.js +++ b/src/account.js @@ -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) {