|
|
@ -2,6 +2,7 @@ import { Readable } from 'stream'; |
|
|
|
import { Process, Processor } from '@nestjs/bull'; |
|
|
|
import { Process, Processor } from '@nestjs/bull'; |
|
|
|
import { Job } from 'bull'; |
|
|
|
import { Job } from 'bull'; |
|
|
|
import papaparse from 'papaparse'; |
|
|
|
import papaparse from 'papaparse'; |
|
|
|
|
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { Base, Column, Model, Project } from '../../../models'; |
|
|
|
import { Base, Column, Model, Project } from '../../../models'; |
|
|
|
import { ProjectsService } from '../../../services/projects.service'; |
|
|
|
import { ProjectsService } from '../../../services/projects.service'; |
|
|
|
import { findWithIdentifier } from '../../../helpers/exportImportHelpers'; |
|
|
|
import { findWithIdentifier } from '../../../helpers/exportImportHelpers'; |
|
|
@ -13,6 +14,28 @@ import type { LinkToAnotherRecordColumn } from '../../../models'; |
|
|
|
|
|
|
|
|
|
|
|
const DEBUG = false; |
|
|
|
const DEBUG = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const debugLog = function (...args: any[]) { |
|
|
|
|
|
|
|
if (DEBUG) { |
|
|
|
|
|
|
|
console.log(...args); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const initTime = function () { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
hrTime: process.hrtime(), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const elapsedTime = function ( |
|
|
|
|
|
|
|
time: { hrTime: [number, number] }, |
|
|
|
|
|
|
|
label?: string, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
const elapsedS = process.hrtime(time.hrTime)[0].toFixed(3); |
|
|
|
|
|
|
|
const elapsedMs = process.hrtime(time.hrTime)[1] / 1000000; |
|
|
|
|
|
|
|
if (label) debugLog(`${label}: ${elapsedS}s ${elapsedMs}ms`); |
|
|
|
|
|
|
|
time.hrTime = process.hrtime(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@Processor(JOBS_QUEUE) |
|
|
|
@Processor(JOBS_QUEUE) |
|
|
|
export class DuplicateProcessor { |
|
|
|
export class DuplicateProcessor { |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
@ -24,6 +47,8 @@ export class DuplicateProcessor { |
|
|
|
|
|
|
|
|
|
|
|
@Process(JobTypes.DuplicateBase) |
|
|
|
@Process(JobTypes.DuplicateBase) |
|
|
|
async duplicateBase(job: Job) { |
|
|
|
async duplicateBase(job: Job) { |
|
|
|
|
|
|
|
const hrTime = initTime(); |
|
|
|
|
|
|
|
|
|
|
|
const { projectId, baseId, dupProjectId, req } = job.data; |
|
|
|
const { projectId, baseId, dupProjectId, req } = job.data; |
|
|
|
|
|
|
|
|
|
|
|
const project = await Project.get(projectId); |
|
|
|
const project = await Project.get(projectId); |
|
|
@ -35,21 +60,6 @@ export class DuplicateProcessor { |
|
|
|
throw new Error(`Project or base not found!`); |
|
|
|
throw new Error(`Project or base not found!`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let start = process.hrtime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const debugLog = function (...args: any[]) { |
|
|
|
|
|
|
|
if (DEBUG) { |
|
|
|
|
|
|
|
console.log(...args); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const elapsedTime = function (label?: string) { |
|
|
|
|
|
|
|
const elapsedS = process.hrtime(start)[0].toFixed(3); |
|
|
|
|
|
|
|
const elapsedMs = process.hrtime(start)[1] / 1000000; |
|
|
|
|
|
|
|
if (label) debugLog(`${label}: ${elapsedS}s ${elapsedMs}ms`); |
|
|
|
|
|
|
|
start = process.hrtime(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const user = (req as any).user; |
|
|
|
const user = (req as any).user; |
|
|
|
|
|
|
|
|
|
|
|
const models = (await base.getModels()).filter( |
|
|
|
const models = (await base.getModels()).filter( |
|
|
@ -61,7 +71,7 @@ export class DuplicateProcessor { |
|
|
|
modelIds: models.map((m) => m.id), |
|
|
|
modelIds: models.map((m) => m.id), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime('serializeModels'); |
|
|
|
elapsedTime(hrTime, 'serializeModels'); |
|
|
|
|
|
|
|
|
|
|
|
if (!exportedModels) { |
|
|
|
if (!exportedModels) { |
|
|
|
throw new Error(`Export failed for base '${base.id}'`); |
|
|
|
throw new Error(`Export failed for base '${base.id}'`); |
|
|
@ -69,24 +79,160 @@ export class DuplicateProcessor { |
|
|
|
|
|
|
|
|
|
|
|
await dupProject.getBases(); |
|
|
|
await dupProject.getBases(); |
|
|
|
|
|
|
|
|
|
|
|
const dupBaseId = dupProject.bases[0].id; |
|
|
|
const dupBase = dupProject.bases[0]; |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime('projectCreate'); |
|
|
|
elapsedTime(hrTime, 'projectCreate'); |
|
|
|
|
|
|
|
|
|
|
|
const idMap = await this.importService.importModels({ |
|
|
|
const idMap = await this.importService.importModels({ |
|
|
|
user, |
|
|
|
user, |
|
|
|
projectId: dupProject.id, |
|
|
|
projectId: dupProject.id, |
|
|
|
baseId: dupBaseId, |
|
|
|
baseId: dupBase.id, |
|
|
|
data: exportedModels, |
|
|
|
data: exportedModels, |
|
|
|
req: req, |
|
|
|
req: req, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime('importModels'); |
|
|
|
elapsedTime(hrTime, 'importModels'); |
|
|
|
|
|
|
|
|
|
|
|
if (!idMap) { |
|
|
|
if (!idMap) { |
|
|
|
throw new Error(`Import failed for base '${base.id}'`); |
|
|
|
throw new Error(`Import failed for base '${base.id}'`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.importModelsData({ |
|
|
|
|
|
|
|
idMap, |
|
|
|
|
|
|
|
sourceProject: project, |
|
|
|
|
|
|
|
sourceModels: models, |
|
|
|
|
|
|
|
destProject: dupProject, |
|
|
|
|
|
|
|
destBase: dupBase, |
|
|
|
|
|
|
|
hrTime, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.projectsService.projectUpdate({ |
|
|
|
|
|
|
|
projectId: dupProject.id, |
|
|
|
|
|
|
|
project: { |
|
|
|
|
|
|
|
status: null, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
if (dupProject?.id) { |
|
|
|
|
|
|
|
await this.projectsService.projectSoftDelete({ |
|
|
|
|
|
|
|
projectId: dupProject.id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw e; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Process(JobTypes.DuplicateModel) |
|
|
|
|
|
|
|
async duplicateModel(job: Job) { |
|
|
|
|
|
|
|
const hrTime = initTime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { projectId, baseId, modelId, title, req } = job.data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const project = await Project.get(projectId); |
|
|
|
|
|
|
|
const base = await Base.get(baseId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const user = (req as any).user; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const models = (await base.getModels()).filter( |
|
|
|
|
|
|
|
(m) => !m.mm && m.type === 'table', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sourceModel = models.find((m) => m.id === modelId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await sourceModel.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const relatedModelIds = sourceModel.columns |
|
|
|
|
|
|
|
.filter((col) => col.uidt === UITypes.LinkToAnotherRecord) |
|
|
|
|
|
|
|
.map((col) => col.colOptions.fk_related_model_id) |
|
|
|
|
|
|
|
.filter((id) => id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const relatedModels = models.filter((m) => relatedModelIds.includes(m.id)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const exportedModel = ( |
|
|
|
|
|
|
|
await this.exportService.serializeModels({ |
|
|
|
|
|
|
|
modelIds: [modelId], |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
)[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elapsedTime(hrTime, 'serializeModel'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!exportedModel) { |
|
|
|
|
|
|
|
throw new Error(`Export failed for base '${base.id}'`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exportedModel.model.title = title; |
|
|
|
|
|
|
|
exportedModel.model.table_name = title.toLowerCase().replace(/ /g, '_'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const idMap = await this.importService.importModels({ |
|
|
|
|
|
|
|
projectId, |
|
|
|
|
|
|
|
baseId, |
|
|
|
|
|
|
|
data: [exportedModel], |
|
|
|
|
|
|
|
user, |
|
|
|
|
|
|
|
req, |
|
|
|
|
|
|
|
externalModels: relatedModels, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elapsedTime(hrTime, 'reimportModelSchema'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!idMap) { |
|
|
|
|
|
|
|
throw new Error(`Import failed for model '${modelId}'`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fields: Record<string, string[]> = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const md of relatedModels) { |
|
|
|
|
|
|
|
const bts = md.columns |
|
|
|
|
|
|
|
.filter( |
|
|
|
|
|
|
|
(c) => |
|
|
|
|
|
|
|
c.uidt === UITypes.LinkToAnotherRecord && |
|
|
|
|
|
|
|
c.colOptions.type === 'bt' && |
|
|
|
|
|
|
|
c.colOptions.fk_related_model_id === modelId, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.map((c) => c.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bts.length > 0) { |
|
|
|
|
|
|
|
fields[md.id] = [md.primaryKey.id]; |
|
|
|
|
|
|
|
fields[md.id].push(...bts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.importModelsData({ |
|
|
|
|
|
|
|
idMap, |
|
|
|
|
|
|
|
sourceProject: project, |
|
|
|
|
|
|
|
sourceModels: [sourceModel], |
|
|
|
|
|
|
|
destProject: project, |
|
|
|
|
|
|
|
destBase: base, |
|
|
|
|
|
|
|
hrTime, |
|
|
|
|
|
|
|
modelFieldIds: fields, |
|
|
|
|
|
|
|
externalModels: relatedModels, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elapsedTime(hrTime, 'reimportModelData'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('exportedModel', exportedModel);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async importModelsData(param: { |
|
|
|
|
|
|
|
idMap: Map<string, string>; |
|
|
|
|
|
|
|
sourceProject: Project; |
|
|
|
|
|
|
|
sourceModels: Model[]; |
|
|
|
|
|
|
|
destProject: Project; |
|
|
|
|
|
|
|
destBase: Base; |
|
|
|
|
|
|
|
hrTime: { hrTime: [number, number] }; |
|
|
|
|
|
|
|
modelFieldIds?: Record<string, string[]>; |
|
|
|
|
|
|
|
externalModels?: Model[]; |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
idMap, |
|
|
|
|
|
|
|
sourceProject, |
|
|
|
|
|
|
|
sourceModels, |
|
|
|
|
|
|
|
destProject, |
|
|
|
|
|
|
|
destBase, |
|
|
|
|
|
|
|
hrTime, |
|
|
|
|
|
|
|
modelFieldIds, |
|
|
|
|
|
|
|
externalModels, |
|
|
|
|
|
|
|
} = param; |
|
|
|
|
|
|
|
|
|
|
|
const handledLinks = []; |
|
|
|
const handledLinks = []; |
|
|
|
const lChunks: Record<string, any[]> = {}; // fk_mm_model_id: { rowId, childId }[]
|
|
|
|
const lChunks: Record<string, any[]> = {}; // fk_mm_model_id: { rowId, childId }[]
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +241,7 @@ export class DuplicateProcessor { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (v.length === 0) continue; |
|
|
|
if (v.length === 0) continue; |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
projectName: dupProject.id, |
|
|
|
projectName: destProject.id, |
|
|
|
tableName: k, |
|
|
|
tableName: k, |
|
|
|
body: v, |
|
|
|
body: v, |
|
|
|
cookie: null, |
|
|
|
cookie: null, |
|
|
@ -110,7 +256,7 @@ export class DuplicateProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for (const sourceModel of models) { |
|
|
|
for (const sourceModel of sourceModels) { |
|
|
|
const dataStream = new Readable({ |
|
|
|
const dataStream = new Readable({ |
|
|
|
read() {}, |
|
|
|
read() {}, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -122,7 +268,7 @@ export class DuplicateProcessor { |
|
|
|
this.exportService.streamModelData({ |
|
|
|
this.exportService.streamModelData({ |
|
|
|
dataStream, |
|
|
|
dataStream, |
|
|
|
linkStream, |
|
|
|
linkStream, |
|
|
|
projectId: project.id, |
|
|
|
projectId: sourceProject.id, |
|
|
|
modelId: sourceModel.id, |
|
|
|
modelId: sourceModel.id, |
|
|
|
handledMmList: handledLinks, |
|
|
|
handledMmList: handledLinks, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -130,9 +276,7 @@ export class DuplicateProcessor { |
|
|
|
const headers: string[] = []; |
|
|
|
const headers: string[] = []; |
|
|
|
let chunk = []; |
|
|
|
let chunk = []; |
|
|
|
|
|
|
|
|
|
|
|
const model = await Model.get( |
|
|
|
const model = await Model.get(findWithIdentifier(idMap, sourceModel.id)); |
|
|
|
findWithIdentifier(idMap, sourceModel.id), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await new Promise((resolve) => { |
|
|
|
await new Promise((resolve) => { |
|
|
|
papaparse.parse(dataStream, { |
|
|
|
papaparse.parse(dataStream, { |
|
|
@ -144,12 +288,12 @@ export class DuplicateProcessor { |
|
|
|
const id = idMap.get(header); |
|
|
|
const id = idMap.get(header); |
|
|
|
if (id) { |
|
|
|
if (id) { |
|
|
|
const col = await Column.get({ |
|
|
|
const col = await Column.get({ |
|
|
|
base_id: dupBaseId, |
|
|
|
base_id: destBase.id, |
|
|
|
colId: id, |
|
|
|
colId: id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (col.colOptions?.type === 'bt') { |
|
|
|
if (col.colOptions?.type === 'bt') { |
|
|
|
const childCol = await Column.get({ |
|
|
|
const childCol = await Column.get({ |
|
|
|
base_id: dupBaseId, |
|
|
|
base_id: destBase.id, |
|
|
|
colId: col.colOptions.fk_child_column_id, |
|
|
|
colId: col.colOptions.fk_child_column_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
headers.push(childCol.column_name); |
|
|
|
headers.push(childCol.column_name); |
|
|
@ -174,7 +318,7 @@ export class DuplicateProcessor { |
|
|
|
parser.pause(); |
|
|
|
parser.pause(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
projectName: dupProject.id, |
|
|
|
projectName: destProject.id, |
|
|
|
tableName: model.id, |
|
|
|
tableName: model.id, |
|
|
|
body: chunk, |
|
|
|
body: chunk, |
|
|
|
cookie: null, |
|
|
|
cookie: null, |
|
|
@ -195,7 +339,7 @@ export class DuplicateProcessor { |
|
|
|
if (chunk.length > 0) { |
|
|
|
if (chunk.length > 0) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
await this.bulkDataService.bulkDataInsert({ |
|
|
|
projectName: dupProject.id, |
|
|
|
projectName: destProject.id, |
|
|
|
tableName: model.id, |
|
|
|
tableName: model.id, |
|
|
|
body: chunk, |
|
|
|
body: chunk, |
|
|
|
cookie: null, |
|
|
|
cookie: null, |
|
|
@ -259,7 +403,7 @@ export class DuplicateProcessor { |
|
|
|
await insertChunks(); |
|
|
|
await insertChunks(); |
|
|
|
|
|
|
|
|
|
|
|
const col = await Column.get({ |
|
|
|
const col = await Column.get({ |
|
|
|
base_id: dupBaseId, |
|
|
|
base_id: destBase.id, |
|
|
|
colId: findWithIdentifier(idMap, columnId), |
|
|
|
colId: findWithIdentifier(idMap, columnId), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -303,23 +447,116 @@ export class DuplicateProcessor { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime(model.title); |
|
|
|
elapsedTime(hrTime, model.title); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime('links'); |
|
|
|
// update external models (has bt to this model)
|
|
|
|
await this.projectsService.projectUpdate({ |
|
|
|
if (externalModels) { |
|
|
|
projectId: dupProject.id, |
|
|
|
for (const sourceModel of externalModels) { |
|
|
|
project: { |
|
|
|
const fields = modelFieldIds?.[sourceModel.id]; |
|
|
|
status: null, |
|
|
|
|
|
|
|
|
|
|
|
if (!fields) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dataStream = new Readable({ |
|
|
|
|
|
|
|
read() {}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const linkStream = new Readable({ |
|
|
|
|
|
|
|
read() {}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.exportService.streamModelData({ |
|
|
|
|
|
|
|
dataStream, |
|
|
|
|
|
|
|
linkStream, |
|
|
|
|
|
|
|
projectId: sourceProject.id, |
|
|
|
|
|
|
|
modelId: sourceModel.id, |
|
|
|
|
|
|
|
handledMmList: handledLinks, |
|
|
|
|
|
|
|
_fieldIds: fields, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const headers: string[] = []; |
|
|
|
|
|
|
|
let chunk = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const model = await Model.get(sourceModel.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
|
|
|
papaparse.parse(dataStream, { |
|
|
|
|
|
|
|
newline: '\r\n', |
|
|
|
|
|
|
|
step: async (results, parser) => { |
|
|
|
|
|
|
|
if (!headers.length) { |
|
|
|
|
|
|
|
parser.pause(); |
|
|
|
|
|
|
|
for (const header of results.data) { |
|
|
|
|
|
|
|
const id = idMap.get(header); |
|
|
|
|
|
|
|
if (id) { |
|
|
|
|
|
|
|
const col = await Column.get({ |
|
|
|
|
|
|
|
base_id: destBase.id, |
|
|
|
|
|
|
|
colId: id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (col.colOptions?.type === 'bt') { |
|
|
|
|
|
|
|
const childCol = await Column.get({ |
|
|
|
|
|
|
|
base_id: destBase.id, |
|
|
|
|
|
|
|
colId: col.colOptions.fk_child_column_id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
headers.push(childCol.column_name); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
headers.push(col.column_name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
debugLog('header not found', header); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parser.resume(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (results.errors.length === 0) { |
|
|
|
|
|
|
|
const row = {}; |
|
|
|
|
|
|
|
for (let i = 0; i < headers.length; i++) { |
|
|
|
|
|
|
|
if (results.data[i] !== '') { |
|
|
|
|
|
|
|
row[headers[i]] = results.data[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
chunk.push(row); |
|
|
|
|
|
|
|
if (chunk.length > 1000) { |
|
|
|
|
|
|
|
parser.pause(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await this.bulkDataService.bulkDataUpdate({ |
|
|
|
|
|
|
|
projectName: destProject.id, |
|
|
|
|
|
|
|
tableName: model.id, |
|
|
|
|
|
|
|
body: chunk, |
|
|
|
|
|
|
|
cookie: null, |
|
|
|
|
|
|
|
raw: true, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.log(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
chunk = []; |
|
|
|
|
|
|
|
parser.resume(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
complete: async () => { |
|
|
|
|
|
|
|
if (chunk.length > 0) { |
|
|
|
|
|
|
|
console.log('chunk', chunk); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await this.bulkDataService.bulkDataUpdate({ |
|
|
|
|
|
|
|
projectName: destProject.id, |
|
|
|
|
|
|
|
tableName: model.id, |
|
|
|
|
|
|
|
body: chunk, |
|
|
|
|
|
|
|
cookie: null, |
|
|
|
|
|
|
|
raw: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
if (dupProject?.id) { |
|
|
|
console.log(e); |
|
|
|
await this.projectsService.projectSoftDelete({ |
|
|
|
} |
|
|
|
projectId: dupProject.id, |
|
|
|
chunk = []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resolve(null); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elapsedTime(hrTime, `external bt ${model.title}`); |
|
|
|
} |
|
|
|
} |
|
|
|
throw e; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|