only use async

This commit is contained in:
Cassie Tarakajian 2017-12-27 12:18:23 -05:00
parent 00e49d647e
commit 665b1440d3

View file

@ -29,8 +29,13 @@ const CHUNK = 1000;
Project.count({}) Project.count({})
.exec().then(async (numProjects) => { .exec().then(async (numProjects) => {
console.log(numProjects); console.log(numProjects);
for (let i = 0; i < numProjects; i += CHUNK) { let index = 0;
let projects = await Project.find({}).skip(i).limit(CHUNK).exec(); async.whilst(
() => {
return index < numProjects;
},
(whilstCb) => {
let projects = await Project.find({}).skip(index).limit(CHUNK).exec();
async.eachSeries(projects, (project, cb) => { async.eachSeries(projects, (project, cb) => {
console.log(project.name); console.log(project.name);
async.eachSeries(project.files, (file, fileCb) => { async.eachSeries(project.files, (file, fileCb) => {
@ -47,23 +52,14 @@ Project.count({})
}, () => { }, () => {
cb(); cb();
}, () => { }, () => {
console.log('at ' + i); index += CHUNK;
whilstCb();
}); });
}); });
},
() => {
console.log('finished processing all documents.')
process.exit(0);
} }
);
}); });
// Project.find({}, (err, projects) => {
// projects.forEach((project, projectIndex) => {
// console.log(project.name);
// project.files.forEach((file, fileIndex) => {
// if (file.url && file.url.includes('p5.js-webeditor')) {
// file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET);
// }
// project.save((err, savedProject) => {
// console.log(`updated file ${file.url}`);
// process.exit(0);
// });
// });
// });
// });