@@ -29,41 +29,37 @@ const CHUNK = 1000;
29
29
Project . count ( { } )
30
30
. exec ( ) . then ( async ( numProjects ) => {
31
31
console . log ( numProjects ) ;
32
- for ( let i = 0 ; i < numProjects ; i += CHUNK ) {
33
- let projects = await Project . find ( { } ) . skip ( i ) . limit ( CHUNK ) . exec ( ) ;
34
- async . eachSeries ( projects , ( project , cb ) => {
35
- console . log ( project . name ) ;
36
- async . eachSeries ( project . files , ( file , fileCb ) => {
37
- if ( file . url && file . url . includes ( 'p5.js-webeditor' ) ) {
38
- file . url = file . url . replace ( 'p5.js-webeditor' , process . env . S3_BUCKET ) ;
39
- project . save ( ( err , newProject ) => {
40
- console . log ( `updated file ${ file . url } ` ) ;
41
- process . exit ( 0 ) ;
32
+ let index = 0 ;
33
+ async . whilst (
34
+ ( ) => {
35
+ return index < numProjects ;
36
+ } ,
37
+ ( whilstCb ) => {
38
+ let projects = await Project . find ( { } ) . skip ( index ) . limit ( CHUNK ) . exec ( ) ;
39
+ async . eachSeries ( projects , ( project , cb ) => {
40
+ console . log ( project . name ) ;
41
+ async . eachSeries ( project . files , ( file , fileCb ) => {
42
+ if ( file . url && file . url . includes ( 'p5.js-webeditor' ) ) {
43
+ file . url = file . url . replace ( 'p5.js-webeditor' , process . env . S3_BUCKET ) ;
44
+ project . save ( ( err , newProject ) => {
45
+ console . log ( `updated file ${ file . url } ` ) ;
46
+ process . exit ( 0 ) ;
47
+ fileCb ( ) ;
48
+ } ) ;
49
+ } else {
42
50
fileCb ( ) ;
43
- } ) ;
44
- } else {
45
- fileCb ( ) ;
46
- }
47
- } , ( ) => {
48
- cb ( ) ;
49
- } , ( ) => {
50
- console . log ( 'at ' + i ) ;
51
+ }
52
+ } , ( ) => {
53
+ cb ( ) ;
54
+ } , ( ) => {
55
+ index += CHUNK ;
56
+ whilstCb ( ) ;
57
+ } ) ;
51
58
} ) ;
52
- } ) ;
53
- }
59
+ } ,
60
+ ( ) => {
61
+ console . log ( 'finished processing all documents.' )
62
+ process . exit ( 0 ) ;
63
+ }
64
+ ) ;
54
65
} ) ;
55
-
56
- // Project.find({}, (err, projects) => {
57
- // projects.forEach((project, projectIndex) => {
58
- // console.log(project.name);
59
- // project.files.forEach((file, fileIndex) => {
60
- // if (file.url && file.url.includes('p5.js-webeditor')) {
61
- // file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET);
62
- // }
63
- // project.save((err, savedProject) => {
64
- // console.log(`updated file ${file.url}`);
65
- // process.exit(0);
66
- // });
67
- // });
68
- // });
69
- // });
0 commit comments