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

Loading…
Cancel
Save