Browse Source

fix(nocodb): bulk update transaction

pull/5491/head
Wing-Kam Wong 2 years ago
parent
commit
225e99245d
  1. 12
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

12
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -2117,12 +2117,10 @@ class BaseModelSqlv2 {
datas.map((d) => this.model.mapAliasToColumn(d))
);
transaction = await this.dbDriver.transaction();
// await this.beforeUpdateb(updateDatas, transaction);
const prevData = [];
const newData = [];
const updatePkValues = [];
const toBeUpdated = [];
const res = [];
for (const d of updateDatas) {
await this.validate(d);
@ -2133,11 +2131,17 @@ class BaseModelSqlv2 {
}
prevData.push(await this.readByPk(pkValues));
const wherePk = await this._wherePk(pkValues);
await transaction(this.tnPath).update(d).where(wherePk);
res.push(wherePk);
toBeUpdated.push({ d, wherePk });
updatePkValues.push(pkValues);
}
transaction = await this.dbDriver.transaction();
for (const o of toBeUpdated) {
await transaction(this.tnPath).update(o.d).where(o.wherePk);
}
await transaction.commit();
for (const pkValues of updatePkValues) {

Loading…
Cancel
Save