Take id property of username, remove wasteful save on profile lookup.

This commit is contained in:
terakilobyte
2015-06-12 19:16:10 -04:00
parent d07e5351ea
commit 5b2b7e23ae
3 changed files with 6 additions and 10 deletions

View File

@@ -119,13 +119,15 @@ module.exports = function(app) {
*/
function returnUser (req, res, next) {
debug(req.params.username);
User.findOne(
{ where: { username: req.params.username.toLowerCase() } },
{ where: { 'username': req.params.username.toLowerCase() } },
function(err, user) {
if (err) {
debug('Username err: ', err);
return next(err);
}
debug(user);
if (user) {
user.progressTimestamps =
user.progressTimestamps.sort(function(a, b) {
@@ -184,11 +186,6 @@ module.exports = function(app) {
user.currentStreak = 1;
}
user.save(function(err) {
if (err) {
return next(err);
}
var data = {};
var progressTimestamps = user.progressTimestamps;
progressTimestamps.forEach(function(timeStamp) {
@@ -234,7 +231,6 @@ module.exports = function(app) {
currentStreak: user.currentStreak +
(user.currentStreak === 1 ? ' day' : ' days')
});
});
} else {
req.flash('errors', {
msg: "404: We couldn't find a page with that url. " +