From 303d3b51ea364d37130de7b88ca9aa41bc81199e Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 4 May 2018 15:07:02 +0900 Subject: [PATCH] :v: --- cli/clean-drive.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/cli/clean-drive.js b/cli/clean-drive.js index 14eb00279..35766f9a3 100644 --- a/cli/clean-drive.js +++ b/cli/clean-drive.js @@ -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}}}`); - } else { - log(chalk`{red deleted: {bold ${prev._id}}}`); - } + promise.then(([i, file, deleted]) => { + if (deleted) { + log(chalk`{gray ${i}} {red deleted: {bold ${file._id}}}`); + } else { + log(chalk`{gray ${i}} {green skipped: {bold ${file._id}}}`); } log.clear(); console.log();