From c04acbfe76c7f1a98fe0fe1814f438c3651d3781 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Thu, 28 Nov 2024 10:41:20 +0000 Subject: [PATCH 1/2] fix: bulkupsert endpoint --- packages/nocodb/src/db/BaseModelSqlv2.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 1fb785e6ef..35aecae66b 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5332,10 +5332,6 @@ class BaseModelSqlv2 { const dataWithoutPks = []; for (const data of preparedDatas) { - if (!raw) { - await this.prepareNocoData(data, true, cookie); - } - const pkValues = this.extractPksValues(data); if (pkValues !== 'N/A' && pkValues !== undefined) { dataWithPks.push({ pk: pkValues, data }); @@ -5366,6 +5362,9 @@ class BaseModelSqlv2 { } } + await Promise.all(toInsert.map((d) => this.prepareNocoData(d, true, cookie))) + await Promise.all(toUpdate.map((d) => this.prepareNocoData(d, false, cookie))) + trx = await this.dbDriver.transaction(); const updatedPks = []; From 5f7f1121a2174e5c8052c7cc768774987831b6ff Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Thu, 28 Nov 2024 10:41:20 +0000 Subject: [PATCH 2/2] fix: remove promise.all --- packages/nocodb/src/db/BaseModelSqlv2.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 35aecae66b..5884d7aa8f 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5336,6 +5336,7 @@ class BaseModelSqlv2 { if (pkValues !== 'N/A' && pkValues !== undefined) { dataWithPks.push({ pk: pkValues, data }); } else { + await this.prepareNocoData(data, true, cookie) // const insertObj = this.handleValidateBulkInsert(data, columns); dataWithoutPks.push(data); } @@ -5355,16 +5356,15 @@ class BaseModelSqlv2 { for (const { pk, data } of dataWithPks) { if (existingPkSet.has(pk)) { + await this.prepareNocoData(data, false, cookie) toUpdate.push(data); } else { + await this.prepareNocoData(data, true, cookie) // const insertObj = this.handleValidateBulkInsert(data, columns); toInsert.push(data); } } - await Promise.all(toInsert.map((d) => this.prepareNocoData(d, true, cookie))) - await Promise.all(toUpdate.map((d) => this.prepareNocoData(d, false, cookie))) - trx = await this.dbDriver.transaction(); const updatedPks = [];