From b540cc3ae1319c5bb9af73129cd49d8bc8e9a233 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sun, 30 Apr 2023 03:11:06 +0300 Subject: [PATCH] fix: revise link chunks Signed-off-by: mertmit --- .../jobs/export-import/duplicate.processor.ts | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts index b17ad19018..4dfb74d127 100644 --- a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts +++ b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts @@ -86,7 +86,27 @@ export class DuplicateProcessor { } const handledLinks = []; - const lChunk: Record = {}; // fk_mm_model_id: { rowId, childId }[] + const lChunks: Record = {}; // fk_mm_model_id: { rowId, childId }[] + + const insertChunks = async () => { + for (const [k, v] of Object.entries(lChunks)) { + try { + if (v.length === 0) continue; + await this.bulkDataService.bulkDataInsert({ + projectName: dupProject.id, + tableName: k, + body: v, + cookie: null, + chunkSize: 1000, + foreign_key_checks: false, + raw: true, + }); + lChunks[k] = []; + } catch (e) { + console.log(e); + } + } + }; for (const sourceModel of models) { const dataStream = new Readable({ @@ -226,7 +246,7 @@ export class DuplicateProcessor { const mmModelId = mmColumns[columnId].colOptions.fk_mm_model_id; const mm = mmParentChild[mmModelId]; - lChunk[mmModelId].push({ + lChunks[mmModelId].push({ [mm.parent]: parent, [mm.child]: child, }); @@ -234,6 +254,8 @@ export class DuplicateProcessor { // get column for the first time parser.pause(); + await insertChunks(); + const col = await Column.get({ base_id: dupBaseId, colId: findWithIdentifier(idMap, columnId), @@ -257,11 +279,11 @@ export class DuplicateProcessor { const mmModelId = col.colOptions.fk_mm_model_id; // create chunk - lChunk[mmModelId] = []; + lChunks[mmModelId] = []; // push to chunk const mm = mmParentChild[mmModelId]; - lChunk[mmModelId].push({ + lChunks[mmModelId].push({ [mm.parent]: parent, [mm.child]: child, }); @@ -273,6 +295,7 @@ export class DuplicateProcessor { } }, complete: async () => { + await insertChunks(); resolve(null); }, }); @@ -281,22 +304,6 @@ export class DuplicateProcessor { elapsedTime(model.title); } - for (const [k, v] of Object.entries(lChunk)) { - try { - await this.bulkDataService.bulkDataInsert({ - projectName: dupProject.id, - tableName: k, - body: v, - cookie: null, - chunkSize: 1000, - foreign_key_checks: false, - raw: true, - }); - } catch (e) { - console.log(e); - } - } - elapsedTime('links'); await this.projectsService.projectUpdate({ projectId: dupProject.id,