This post route below is timing out about 1/100 times. I am trying to optimize the code to avoid these timeout but they continue to happen. Is there anything I could do to further avoid these request timeouts?
I'm not sure how to troubleshoot this. This route shouldn't take over 30 seconds to post.
Thanks for any help!
router.post("/updateAccount", usernameToLowerCase, async function(req, res){
if (req.user) {
await User.findOne({username: req.body.currentUser}, function(err, user) {
console.log('first ' + user)
if (err) {
console.log('cant find user err' + err)
return done(err);
}
user.username = req.body.username;
user.password = req.body.password;
user.accountUpdated = true;
user.save(function(err){
if (err) {
req.flash("error", "It looks like that email address is taken. Please use a different email address");
res.redirect('back');
} else {
req.logout();
req.login(user, function(err) {
if (err) console.log('There was an account error' + err)
req.flash("success", "Your account has been created! Your username is " + user.username );
res.redirect('/results')
});
}
});
});
}
});