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,41 +29,37 @@ 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(
async.eachSeries(projects, (project, cb) => { () => {
console.log(project.name); return index < numProjects;
async.eachSeries(project.files, (file, fileCb) => { },
if (file.url && file.url.includes('p5.js-webeditor')) { (whilstCb) => {
file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET); let projects = await Project.find({}).skip(index).limit(CHUNK).exec();
project.save((err, newProject) => { async.eachSeries(projects, (project, cb) => {
console.log(`updated file ${file.url}`); console.log(project.name);
process.exit(0); async.eachSeries(project.files, (file, fileCb) => {
if (file.url && file.url.includes('p5.js-webeditor')) {
file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET);
project.save((err, newProject) => {
console.log(`updated file ${file.url}`);
process.exit(0);
fileCb();
});
} else {
fileCb(); fileCb();
}); }
} else { }, () => {
fileCb(); cb();
} }, () => {
}, () => { index += CHUNK;
cb(); whilstCb();
}, () => { });
console.log('at ' + i);
}); });
}); },
} () => {
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);
// });
// });
// });
// });