gpt4 book ai didi

node.js - 请求超时问题 - Node/Heroku

转载 作者:行者123 更新时间:2023-12-04 08:16:13 25 4
gpt4 key购买 nike

下面的这个 post 路由超时大约 1/100 次。我正在尝试优化代码以避免这些超时,但它们继续发生。我可以做些什么来进一步避免这些请求超时?
我不知道如何解决这个问题。这条路线的发布时间不应超过 30 秒。
谢谢你的帮助!

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')

});
}
});
});

}
});

最佳答案

您可以使用 findOneAndUpdate找到匹配的文档,根据更新参数更新它

try{
let filter = {username: req.body.currentUser};
let user = {
username = req.body.username;
password = req.body.password;
accountUpdated = true
}
let user = await User.findOneAndUpdate(filter, user,{
select: "_id username",
new: true,
});
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')
});
}
catch(error){
console.log(error)
req.flash("error", "It looks like that email address is taken. Please use a different email address");
res.redirect('back');
//handle error
}

关于node.js - 请求超时问题 - Node/Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65689323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com