This commit is contained in:
syuilo 2018-05-04 15:07:02 +09:00
parent abfbb068d7
commit bcf28282f6
1 changed files with 19 additions and 15 deletions

View File

@ -16,19 +16,23 @@ async function main() {
for (let i = 0; i < count; i++) {
promiseGens.push(() => {
const promise = new Promise(async (res, rej) => {
function skip() {
res([i, file, false]);
}
const file = await DriveFile.findOne(prev ? {
_id: { $gt: prev._id }
_id: { $lt: prev._id }
} : {}, {
sort: {
_id: 1
_id: -1
}
});
prev = file;
if (file == null) return res();
if (file == null) return skip();
log(chalk`scanning: {bold ${file._id}} ...`);
log(chalk`{gray ${i}} scanning: {bold ${file._id}} ...`);
const attachingUsersCount = await User.count({
$or: [{
@ -37,28 +41,28 @@ async function main() {
bannerId: file._id
}]
}, { limit: 1 });
if (attachingUsersCount !== 0) return res();
if (attachingUsersCount !== 0) return skip();
const attachingNotesCount = await Note.count({
mediaIds: file._id
}, { limit: 1 });
if (attachingNotesCount !== 0) return res();
if (attachingNotesCount !== 0) return skip();
const attachingMessagesCount = await MessagingMessage.count({
fileId: file._id
}, { limit: 1 });
if (attachingMessagesCount !== 0) return res();
if (attachingMessagesCount !== 0) return skip();
deleteDriveFile(file).then(res).catch(rej);
deleteDriveFile(file).then(() => {
res([i, file, true]);
}).catch(rej);
});
promise.then(x => {
if (prev) {
if (x == null) {
log(chalk`{green skipped: {bold ${prev._id}}}`);
promise.then(([i, file, deleted]) => {
if (deleted) {
log(chalk`{gray ${i}} {red deleted: {bold ${file._id}}}`);
} else {
log(chalk`{red deleted: {bold ${prev._id}}}`);
}
log(chalk`{gray ${i}} {green skipped: {bold ${file._id}}}`);
}
log.clear();
console.log();