既旦南 2022-05-03 08:23 采纳率: 33.3%
浏览 60

nodeJS 在使用sequelize ORM 操作 Mysql事务时出现 Maximum call stack size exceeded

我在使用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)来给它一点间隔事件来进行垃圾回收,但是我尝试了之后发现还是不行。

诚请各位小伙伴看看是语法错了出现死循环了还是其他原因

展开全部

  • 写回答

1条回答 默认 最新

  • Heerey525 前端领域新星创作者 2022-05-03 08:43
    关注

    在每个.then console.log输出一下,看哪个环节的问题,很明显是查询非常频繁导致的

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部