Browse Source

fix: improved wherePk handling for bulkUpdate

pull/8315/head
mertmit 3 months ago
parent
commit
7c35ec37e4
  1. 29
      packages/nocodb/src/db/BaseModelSqlv2.ts

29
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2996,8 +2996,8 @@ class BaseModelSqlv2 {
} }
} }
async _wherePk(id) { async _wherePk(id, skipGetColumns = false) {
await this.model.getColumns(); if (!skipGetColumns) await this.model.getColumns();
return _wherePk(this.model.primaryKeys, id); return _wherePk(this.model.primaryKeys, id);
} }
@ -3709,7 +3709,7 @@ class BaseModelSqlv2 {
const newData = []; const newData = [];
const updatePkValues = []; const updatePkValues = [];
const toBeUpdated = []; const toBeUpdated = [];
const toRead = []; const pkAndData: { pk: any; data: any }[] = [];
const readChunkSize = 100; const readChunkSize = 100;
for (const [i, d] of updateDatas.entries()) { for (const [i, d] of updateDatas.entries()) {
const pkValues = this._extractPksValues(d); const pkValues = this._extractPksValues(d);
@ -3723,13 +3723,19 @@ class BaseModelSqlv2 {
if (!raw) { if (!raw) {
await this.prepareNocoData(d, false, cookie); await this.prepareNocoData(d, false, cookie);
toRead.push(pkValues); pkAndData.push({
pk: pkValues,
data: d,
});
if (toRead.length >= readChunkSize || i === updateDatas.length - 1) { if (
const tempToRead = toRead.splice(0, toRead.length); pkAndData.length >= readChunkSize ||
i === updateDatas.length - 1
) {
const tempToRead = pkAndData.splice(0, pkAndData.length);
const oldRecords = await this.list( const oldRecords = await this.list(
{ {
pks: tempToRead.join(','), pks: tempToRead.map((v) => v.pk).join(','),
}, },
{ {
limitOverride: tempToRead.length, limitOverride: tempToRead.length,
@ -3755,11 +3761,14 @@ class BaseModelSqlv2 {
prevData.push(oldRecord); prevData.push(oldRecord);
} }
} }
for (const { pk, data } of tempToRead) {
const wherePk = await this._wherePk(pk, true);
toBeUpdated.push({ d: data, wherePk });
updatePkValues.push(pk);
}
} }
} }
const wherePk = await this._wherePk(pkValues);
toBeUpdated.push({ d, wherePk });
updatePkValues.push(pkValues);
} }
transaction = await this.dbDriver.transaction(); transaction = await this.dbDriver.transaction();

Loading…
Cancel
Save