File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -25,15 +25,15 @@ function * migrateRecords (tableName) {
2525 // Process until all the records from DB is fetched
2626 while ( true ) {
2727 const records = yield dbhelper . scanRecords ( params )
28- const totalRecords = records . Items . length
29- logger . debug ( `Number of ${ tableName } s fetched from DB - ` + totalRecords )
30- for ( let i = 0 ; i < totalRecords ; i ++ ) {
28+ logger . debug ( `Number of ${ tableName } s currently fetched from DB - ` + records . Items . length )
29+ let i = 0
30+ for ( const item of records . Items ) {
3131 const record = {
3232 index : config . get ( 'esConfig.ES_INDEX' ) ,
3333 type : config . get ( 'esConfig.ES_TYPE' ) ,
34- id : records . Items [ i ] . id ,
34+ id : item . id ,
3535 body : {
36- doc : _ . extend ( { resource : helper . camelize ( tableName ) } , records . Items [ i ] ) ,
36+ doc : _ . extend ( { resource : helper . camelize ( tableName ) } , item ) ,
3737 doc_as_upsert : true
3838 }
3939 }
@@ -45,12 +45,16 @@ function * migrateRecords (tableName) {
4545 promises = [ ]
4646 batchCounter ++
4747 }
48+ i ++
4849 }
4950
5051 // Continue fetching the remaining records from Database
5152 if ( typeof records . LastEvaluatedKey !== 'undefined' ) {
5253 params . ExclusiveStartKey = records . LastEvaluatedKey
5354 } else {
55+ if ( promises . length > 0 ) {
56+ yield promises
57+ }
5458 break // If there are no more records to process, exit the loop
5559 }
5660 }
You can’t perform that action at this time.
0 commit comments