finish moving migration of projects to username folder to chunks
This commit is contained in:
parent
899b5c9710
commit
d58d8ea0bd
1 changed files with 56 additions and 32 deletions
|
@ -29,12 +29,20 @@ const CHUNK = 100;
|
|||
Project.count({}).exec().then((numProjects) => {
|
||||
console.log(numProjects);
|
||||
let index = 0;
|
||||
})
|
||||
Project.find({}, (err, projects) => {
|
||||
projects.forEach((project, projectIndex) => {
|
||||
if (!project.user) return;
|
||||
async.whilst(
|
||||
() => {
|
||||
return index < numProjects;
|
||||
},
|
||||
(whilstCb) => {
|
||||
Project.find({}).skip(index).limit(CHUNK).exec((err, projects) => {
|
||||
async.eachSeries(projects, (project, cb) => {
|
||||
if (!project.user) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
const userId = project.user.valueOf();
|
||||
project.files.forEach((file, fileIndex) => {
|
||||
console.log(project.name);
|
||||
async.eachSeries(project.files, (file, fileCb) => {
|
||||
if (file.url && file.url.includes(process.env.S3_BUCKET) && !file.url.includes(userId)) {
|
||||
const key = file.url.split('/').pop();
|
||||
console.log(key);
|
||||
|
@ -53,12 +61,28 @@ Project.find({}, (err, projects) => {
|
|||
`https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}`) + `/${userId}/${key}`;
|
||||
project.save((err, savedProject) => {
|
||||
console.log(`updated file ${key}`);
|
||||
fileCb();
|
||||
});
|
||||
});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
fileCb(e);
|
||||
}
|
||||
} else {
|
||||
fileCb();
|
||||
}
|
||||
}, () => {
|
||||
cb();
|
||||
});
|
||||
}, () => {
|
||||
index += CHUNK;
|
||||
whilstCb();
|
||||
});
|
||||
});
|
||||
},
|
||||
() => {
|
||||
console.log('finished processing all documents.');
|
||||
process.exit(0);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue