我在使用sequelize使用事务操作数据库时,通过Promise来反复查询更新数据库,但是在进行到第六个操作也是最后一个操作时发出了Maximum call stack size exceeded的错误
sequelize.transaction(t=>{
return User.findOne({
attributes:[
'doing',
'doingD',
'remarks',
'user_name'
]
},{
where:{
'id':info.userId
},
transaction:t
}).then(item=>{
if(Object.getOwnPropertyNames(item)==0){
return res.cc('您的账户异常!请联系管理员处理');
}
userInfo = item.dataValues;
return feedback.findOne({
attributes:[
'content',
'feedbackDate',
'actionId',
'tableId'
],
where:{
'id':info.feedbackId
},
transaction:t
})
}).then(item=>{
if(Object.getOwnPropertyNames(item)==0)return res.cc('服务器错误!');
feedbackInfo = item.dataValues;
return feedback.update({
'advice':info.advice,
'adviceuser':userInfo.user_name,
'adviceDate':moment().format('YYYY-MM-DD HH:mm:ss')
},{
where:{
'id':info.feedbackId
},
transaction:t
})
}).then(item=>{
if(item[0]==0){
throw new Error();
}
const doing = `处理了访客于${feedbackInfo.feedbackDate}反馈的${feedbackInfo.content}的信息`;
return userDo.create({
'doing':doing,
'doingDate':moment().format('YYYY-MM-DD HH:mm:ss'),
'userId':info.userId
},{
transaction:t
})
}).then(item=>{
return actionTable.findOne({
attributes:[
'back',
'falseBack',
'hasBack'
],
where:{
'id':feedbackInfo.actionId
}
})
}).then(item=>{
item.dataValues = item;
return actionTable.update({
'falseBack':item.falseBack-1,
'hasBack':item.hasBack+1
},{
where:{
'id':feedbackInfo.actionId
},
transaction:t
})
}).then(item=>{
if(item[0]==0)throw new Error();
return res.cc('处理成功!',0);
}).catch(err=>{
// return res.cc('服务器繁忙错误!');
throw err
})
})
结果就是报错了 RangeError: Maximum call stack size exceeded
我一开始简单把无用的数据删了删,发现并不行;随后在查阅资料的过程中,有小伙伴说给它一个setTimeOut(function(){},0)来给它一点间隔事件来进行垃圾回收,但是我尝试了之后发现还是不行。
诚请各位小伙伴看看是语法错了出现死循环了还是其他原因