@ -97,8 +103,8 @@ export async function importData({
services: AirtableImportContext;
}):Promise<EntityMap>{
try{
// @ts-ignore
constrecords=awaitreadAllData({
// returns EntityMap which allows us to stream data
constrecords: EntityMap=awaitreadAllData({
table,
base,
logDetailed,
@ -109,10 +115,14 @@ export async function importData({
constreadable=records.getStream();
constallRecordsCount=awaitrecords.getCount();
constpromises=[];
lettempData=[];
letimportedCount=0;
letactiveProcess=0;
lettempCount=0;
// we keep track of active process to pause and resume the stream as we have async calls within the stream and we don't want to load all data in memory
letactiveProcess=0;
readable.on('data',async(record)=>{
promises.push(
newPromise(async(resolve)=>{
@ -148,6 +158,7 @@ export async function importData({
allRecordsCount,
)}`,
);
importedCount+=insertArray.length;
insertArray=[];
@ -162,7 +173,10 @@ export async function importData({
);
});
readable.on('end',async()=>{
// ensure all chunks are processed
awaitPromise.all(promises);
// insert remaining data
if(tempData.length>0){
awaitservices.bulkDataService.bulkDataInsert({
projectName,
@ -182,6 +196,7 @@ export async function importData({
importedCount+=tempData.length;
tempData=[];
}
resolve(true);
});
});
@ -230,7 +245,7 @@ export async function importLTARData({
curCol:{title?: string};
refCol:{title?: string};
}>=[];
constallData=
constallData: EntityMap=
records||
(awaitreadAllData({
table,
@ -288,12 +303,13 @@ export async function importLTARData({
forawait(constassocMetaofassocTableMetas){
letassocTableData=[];
letimportedCount=0;
lettempCount=0;
// extract insert data from records
// extract link data from records
awaitnewPromise((resolve)=>{
constpromises=[];
constreadable=allData.getStream();
lettempCount=0;
readable.on('data',async(record)=>{
promises.push(
newPromise(async(resolve)=>{
@ -318,6 +334,7 @@ export async function importLTARData({
0,
assocTableData.length,
);
logBasic(
`:: Importing '${
table.title
@ -346,7 +363,10 @@ export async function importLTARData({
);
});
readable.on('end',async()=>{
// ensure all chunks are processed
awaitPromise.all(promises);
// insert remaining data
if(assocTableData.length>=0){
logBasic(
`:: Importing '${
@ -367,6 +387,7 @@ export async function importLTARData({