Javascript 博士后;对于每一个“;RangeError:超出了最大调用堆栈大小
我使用的是sequelize,我有一个使用findOrCreate的函数,但是它似乎抛出并出错“RangeError:超出了最大调用堆栈大小”,尽管有时会添加条目 下面是我使用的代码,我将以6 tid的速度通过它。是否有人知道发生了什么以及如何解决/预防Javascript 博士后;对于每一个“;RangeError:超出了最大调用堆栈大小,javascript,node.js,postgresql,Javascript,Node.js,Postgresql,我使用的是sequelize,我有一个使用findOrCreate的函数,但是它似乎抛出并出错“RangeError:超出了最大调用堆栈大小”,尽管有时会添加条目 下面是我使用的代码,我将以6 tid的速度通过它。是否有人知道发生了什么以及如何解决/预防 exports.sqlAddTags = async function(did, tids) { try { await sequelize.authenticate(); const promises
exports.sqlAddTags = async function(did, tids) {
try {
await sequelize.authenticate();
const promises = [];
tids.forEach(t =>{
console.log(did, t)
promises.push(FB_Tag.findOrCreate({
where: {
did: did,
tid: t
}
}));
});
return await Promise.all(promises);
} catch (e) {
console.log(e.message)
}
};
我的模型:
FB_Tag.init({
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
did: {
type: Sequelize.STRING,
allowNull: false,
},
tid: {
type: Sequelize.STRING,
allowNull: false
},
}, {
sequelize,
modelName: 'fb_tag',
timestamps: false
});
编辑:似乎只有一个tid,它也抛出了这个错误
如果该项目已存在,我似乎收到此消息。不确定这是否正常
CREATE OR REPLACE FUNCTION pg_temp.testfunc(OUT response "public"."fb_tags", OUT sequelize_caught_exception text) RETURNS RECORD AS $func_66aef14340b2417dabf18d3cdfafa589$ BEGIN INSERT INTO "public"."fb_tags" ("i
d","did","tid") VALUES (DEFAULT,'jcBUnwocFS9I7RekMZHJ','7AQS1zPkLIUsSfx8lC0a') RETURNING * INTO response; EXCEPTION WHEN unique_violation THEN GET STACKED DIAGNOSTICS sequelize_caught_exception = PG_EXCEPTION_DETAIL; END $func_66aef14340b2417dabf18d3cdfafa589$ LANG
UAGE plpgsql; SELECT (testfunc.response).*, testfunc.sequelize_caught_exception FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc();
我已经创建了一个测试脚本,它的逻辑与上面的相同,因此我只能将此作为函数调用的方式
const newTags = [];
const oldTags = [];
const postgresTags = []
data.tags.forEach(t => {
if(t.id === t.title) {
newTags.push(t.title)
} else {
oldTags.push(t.id);
postgresTags.push(t.id)
}
});
if(oldTags.length > 0) {
await firestoreAddTagsToDesign(context.auth.uid, oldTags, data.did, "old");
}
if(newTags.length > 0) {
const setTags = await firestoreAddNewTags(context.auth.uid, newTags, data.did);
await firestoreAddTagsToDesign(context.auth.uid, setTags, data.did, "new");
setTags.forEach(i => postgresTags.push(i.id));
}
await sqlAddTags(data.did, postgresTags);
这个错误表明PostgreSQL中有一个无止境的循环。我不知道怎么做。我已经注销了循环及其周围的所有内容,它只执行一次函数,循环的长度与我传递的数组长度相同,我会记录实际执行的SQL语句并从那里开始。只是添加了一些注销的内容,但我不确定这是否是Postgres的正常行为?该SQL语句似乎与错误消息没有关联。