|
|
@ -1,5 +1,6 @@ |
|
|
|
/* eslint-disable no-async-promise-executor */ |
|
|
|
/* eslint-disable no-async-promise-executor */ |
|
|
|
import { RelationTypes, UITypes } from 'nocodb-sdk'; |
|
|
|
import { RelationTypes, UITypes } from 'nocodb-sdk'; |
|
|
|
|
|
|
|
import sizeof from 'object-sizeof'; |
|
|
|
import EntityMap from './EntityMap'; |
|
|
|
import EntityMap from './EntityMap'; |
|
|
|
import type { BulkDataAliasService } from '../../../../../services/bulk-data-alias.service'; |
|
|
|
import type { BulkDataAliasService } from '../../../../../services/bulk-data-alias.service'; |
|
|
|
import type { TablesService } from '../../../../../services/tables.service'; |
|
|
|
import type { TablesService } from '../../../../../services/tables.service'; |
|
|
@ -7,8 +8,8 @@ import type { TablesService } from '../../../../../services/tables.service'; |
|
|
|
import type { AirtableBase } from 'airtable/lib/airtable_base'; |
|
|
|
import type { AirtableBase } from 'airtable/lib/airtable_base'; |
|
|
|
import type { TableType } from 'nocodb-sdk'; |
|
|
|
import type { TableType } from 'nocodb-sdk'; |
|
|
|
|
|
|
|
|
|
|
|
const BULK_DATA_BATCH_SIZE = 500; |
|
|
|
const BULK_DATA_BATCH_COUNT = 100; // check size for every 100 records
|
|
|
|
const ASSOC_BULK_DATA_BATCH_SIZE = 1000; |
|
|
|
const BULK_DATA_BATCH_SIZE = 102400; // in bytes
|
|
|
|
const BULK_PARALLEL_PROCESS = 5; |
|
|
|
const BULK_PARALLEL_PROCESS = 5; |
|
|
|
|
|
|
|
|
|
|
|
interface AirtableImportContext { |
|
|
|
interface AirtableImportContext { |
|
|
@ -122,27 +123,28 @@ export async function importData({ |
|
|
|
fields, |
|
|
|
fields, |
|
|
|
}); |
|
|
|
}); |
|
|
|
tempData.push(r); |
|
|
|
tempData.push(r); |
|
|
|
|
|
|
|
if (tempData.length % BULK_DATA_BATCH_COUNT === 0) { |
|
|
|
if (tempData.length >= BULK_DATA_BATCH_SIZE) { |
|
|
|
if (sizeof(tempData) >= BULK_DATA_BATCH_SIZE) { |
|
|
|
let insertArray = tempData.splice(0, tempData.length); |
|
|
|
let insertArray = tempData.splice(0, tempData.length); |
|
|
|
|
|
|
|
|
|
|
|
await services.bulkDataService.bulkDataInsert({ |
|
|
|
await services.bulkDataService.bulkDataInsert({ |
|
|
|
projectName, |
|
|
|
projectName, |
|
|
|
tableName: table.title, |
|
|
|
tableName: table.title, |
|
|
|
body: insertArray, |
|
|
|
body: insertArray, |
|
|
|
cookie: {}, |
|
|
|
cookie: {}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
logBasic( |
|
|
|
logBasic( |
|
|
|
`:: Importing '${ |
|
|
|
`:: Importing '${ |
|
|
|
table.title |
|
|
|
table.title |
|
|
|
}' data :: ${importedCount} - ${Math.min( |
|
|
|
}' data :: ${importedCount} - ${Math.min( |
|
|
|
importedCount + BULK_DATA_BATCH_SIZE, |
|
|
|
importedCount + insertArray.length, |
|
|
|
allRecordsCount, |
|
|
|
allRecordsCount, |
|
|
|
)}`,
|
|
|
|
)}`,
|
|
|
|
); |
|
|
|
); |
|
|
|
importedCount += insertArray.length; |
|
|
|
importedCount += insertArray.length; |
|
|
|
insertArray = []; |
|
|
|
insertArray = []; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
activeProcess--; |
|
|
|
activeProcess--; |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
@ -164,7 +166,7 @@ export async function importData({ |
|
|
|
`:: Importing '${ |
|
|
|
`:: Importing '${ |
|
|
|
table.title |
|
|
|
table.title |
|
|
|
}' data :: ${importedCount} - ${Math.min( |
|
|
|
}' data :: ${importedCount} - ${Math.min( |
|
|
|
importedCount + BULK_DATA_BATCH_SIZE, |
|
|
|
importedCount + tempData.length, |
|
|
|
allRecordsCount, |
|
|
|
allRecordsCount, |
|
|
|
)}`,
|
|
|
|
)}`,
|
|
|
|
); |
|
|
|
); |
|
|
@ -300,26 +302,31 @@ export async function importLTARData({ |
|
|
|
})), |
|
|
|
})), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (assocTableData.length >= ASSOC_BULK_DATA_BATCH_SIZE) { |
|
|
|
if (assocTableData.length % BULK_DATA_BATCH_COUNT === 0) { |
|
|
|
let insertArray = assocTableData.splice(0, assocTableData.length); |
|
|
|
if (sizeof(assocTableData) >= BULK_DATA_BATCH_SIZE) { |
|
|
|
logBasic( |
|
|
|
let insertArray = assocTableData.splice( |
|
|
|
`:: Importing '${ |
|
|
|
0, |
|
|
|
table.title |
|
|
|
assocTableData.length, |
|
|
|
}' LTAR data :: ${importedCount} - ${Math.min( |
|
|
|
); |
|
|
|
importedCount + ASSOC_BULK_DATA_BATCH_SIZE, |
|
|
|
logBasic( |
|
|
|
insertArray.length, |
|
|
|
`:: Importing '${ |
|
|
|
)}`,
|
|
|
|
table.title |
|
|
|
); |
|
|
|
}' LTAR data :: ${importedCount} - ${Math.min( |
|
|
|
|
|
|
|
importedCount + insertArray.length, |
|
|
|
await services.bulkDataService.bulkDataInsert({ |
|
|
|
insertArray.length, |
|
|
|
projectName, |
|
|
|
)}`,
|
|
|
|
tableName: assocMeta.modelMeta.title, |
|
|
|
); |
|
|
|
body: insertArray, |
|
|
|
|
|
|
|
cookie: {}, |
|
|
|
await services.bulkDataService.bulkDataInsert({ |
|
|
|
}); |
|
|
|
projectName, |
|
|
|
|
|
|
|
tableName: assocMeta.modelMeta.title, |
|
|
|
importedCount += insertArray.length; |
|
|
|
body: insertArray, |
|
|
|
insertArray = []; |
|
|
|
cookie: {}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
importedCount += insertArray.length; |
|
|
|
|
|
|
|
insertArray = []; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
activeProcess--; |
|
|
|
activeProcess--; |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
@ -334,7 +341,7 @@ export async function importLTARData({ |
|
|
|
`:: Importing '${ |
|
|
|
`:: Importing '${ |
|
|
|
table.title |
|
|
|
table.title |
|
|
|
}' LTAR data :: ${importedCount} - ${Math.min( |
|
|
|
}' LTAR data :: ${importedCount} - ${Math.min( |
|
|
|
importedCount + ASSOC_BULK_DATA_BATCH_SIZE, |
|
|
|
importedCount + assocTableData.length, |
|
|
|
assocTableData.length, |
|
|
|
assocTableData.length, |
|
|
|
)}`,
|
|
|
|
)}`,
|
|
|
|
); |
|
|
|
); |
|
|
|