Когда для следующего кода сделан параллельный запрос, одновременно выполняются две транзакции.
- Первое обновление (столбцы мягкого удаления)
- Затем вставляются строки
Для двух транзакций из-за одновременного запроса сначала выполняются два обновления, а затем из обеих транзакций вставляются строки.Как решить эту проблему.
execute(aid, id, d) {
const _self = this;
this.db.transaction({autocommit: false, isolationLevel: this.db.Transaction.ISOLATION_LEVELS.SERIALIZABLE},
function (t)
{
_self.modal.destroy({
where: {
aid : aid
}
})
.then((result) => {
let promises = [];
for(let i=0; i<data.length; i++) {
promises.push(new Promise(function(resolve, reject) {
_self.modal.create({
val: d[i].val,
id: id,
}).then((s) => {
let hold = []
for(let j=0; j<data[i].hold.length; j++) {
hold.push(_self.addDist(id, aid, s.id, d[i].hold[j]))
}
Promise.all(hold).then(() => {
resolve();
})
}).error(error => {
// error
});
}));
}
return Promise.all(promises);
}).then(() => {
_self.modal.findOne({
where: {
id: id,
},
include: [{}]
}).then(e => {
//success
}).catch(error => {
console.log(error);
});
})
}).catch(function (error)
{
console.log('rolling back as got error ', error);
});