From 225e99245d08f5ec558c438ee635f95acbfe69ab Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 17 Apr 2023 12:42:47 +0800 Subject: [PATCH] fix(nocodb): bulk update transaction --- .../lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 453af0f141..426445c431 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/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) {