From 69c452a9809d0af933b3137651b9a18327d3e8a7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 15 Apr 2018 11:57:33 +0900 Subject: [PATCH] :pizza: --- cli/del-usr.js | 13 + {tools => cli}/init.js | 0 {tools/migration => migration}/README.md | 0 {tools => migration}/init-migration-file.sh | 0 src/models/drive-file.ts | 9 +- src/models/note.ts | 4 + src/models/user.ts | 4 + tools/migration/nighthike/1.js | 39 --- tools/migration/nighthike/10.js | 3 - tools/migration/nighthike/11.js | 36 --- tools/migration/nighthike/12.js | 58 ----- tools/migration/nighthike/2.js | 39 --- tools/migration/nighthike/3.js | 73 ------ tools/migration/nighthike/4.js | 262 -------------------- tools/migration/nighthike/5.js | 49 ---- tools/migration/nighthike/6.js | 13 - tools/migration/nighthike/7.js | 41 --- tools/migration/nighthike/8.js | 40 --- tools/migration/nighthike/9.js | 93 ------- 19 files changed, 28 insertions(+), 748 deletions(-) create mode 100644 cli/del-usr.js rename {tools => cli}/init.js (100%) rename {tools/migration => migration}/README.md (100%) rename {tools => migration}/init-migration-file.sh (100%) mode change 100755 => 100644 delete mode 100644 tools/migration/nighthike/1.js delete mode 100644 tools/migration/nighthike/10.js delete mode 100644 tools/migration/nighthike/11.js delete mode 100644 tools/migration/nighthike/12.js delete mode 100644 tools/migration/nighthike/2.js delete mode 100644 tools/migration/nighthike/3.js delete mode 100644 tools/migration/nighthike/4.js delete mode 100644 tools/migration/nighthike/5.js delete mode 100644 tools/migration/nighthike/6.js delete mode 100644 tools/migration/nighthike/7.js delete mode 100644 tools/migration/nighthike/8.js delete mode 100644 tools/migration/nighthike/9.js diff --git a/cli/del-usr.js b/cli/del-usr.js new file mode 100644 index 0000000000..08e97845ec --- /dev/null +++ b/cli/del-usr.js @@ -0,0 +1,13 @@ +const deleteUser = require('../built/models/user').deleteUser; + +const args = process.argv.slice(2); + +const userId = args[0]; + +console.log(`deleting ${userId}...`); + +deleteUser(userId).then(() => { + console.log('done'); +}, e => { + console.error(e); +}); diff --git a/tools/init.js b/cli/init.js similarity index 100% rename from tools/init.js rename to cli/init.js diff --git a/tools/migration/README.md b/migration/README.md similarity index 100% rename from tools/migration/README.md rename to migration/README.md diff --git a/tools/init-migration-file.sh b/migration/init-migration-file.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/init-migration-file.sh rename to migration/init-migration-file.sh diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 80fe8e0300..fc9c150724 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -84,14 +84,19 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv // このDriveFileがアバターやバナーに使われていたらそれらのプロパティをnullにする const u = await User.findOne({ _id: d.metadata.userId }); if (u) { - if (u.avatarId.equals(d._id)) { + if (u.avatarId && u.avatarId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { avatarId: null } }); } - if (u.bannerId.equals(d._id)) { + if (u.bannerId && u.bannerId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { bannerId: null } }); } } + // このDriveFileのチャンクをすべて削除 + await monkDb.get('driveFiles.chunks').remove({ + files_id: d._id + }); + // このDriveFileを削除 await DriveFile.remove({ _id: d._id diff --git a/src/models/note.ts b/src/models/note.ts index 1dcc70c175..3059593540 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -91,6 +91,8 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { n = note as INote; } + console.log(n == null ? `Note: delete skipped ${note}` : `Note: deleting ${n._id}`); + if (n == null) return; // このNoteへの返信をすべて削除 @@ -132,6 +134,8 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { await Note.remove({ _id: n._id }); + + console.log(`Note: deleted ${n._id}`); } /** diff --git a/src/models/user.ts b/src/models/user.ts index f18206120f..449a563002 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -155,6 +155,8 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { u = user as IUser; } + console.log(u == null ? `User: delete skipped ${user}` : `User: deleting ${u._id}`); + if (u == null) return; // このユーザーのAccessTokenをすべて削除 @@ -261,6 +263,8 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await User.remove({ _id: u._id }); + + console.log(`User: deleted ${u._id}`); } /** diff --git a/tools/migration/nighthike/1.js b/tools/migration/nighthike/1.js deleted file mode 100644 index 6ae30ad4f9..0000000000 --- a/tools/migration/nighthike/1.js +++ /dev/null @@ -1,39 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/models/user'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (user) => { - const result = await User.update(user._id, { - $set: { - 'username': user.username.replace(/\-/g, '_'), - 'username_lower': user.username_lower.replace(/\-/g, '_') - } - }); - return result.ok === 1; -} - -async function main() { - const count = await User.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await User.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/10.js b/tools/migration/nighthike/10.js deleted file mode 100644 index 3c57b8d484..0000000000 --- a/tools/migration/nighthike/10.js +++ /dev/null @@ -1,3 +0,0 @@ -db.following.remove({ - deletedAt: { $exists: true } -}); diff --git a/tools/migration/nighthike/11.js b/tools/migration/nighthike/11.js deleted file mode 100644 index 2a4e8630d4..0000000000 --- a/tools/migration/nighthike/11.js +++ /dev/null @@ -1,36 +0,0 @@ -db.pollVotes.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.postReactions.renameCollection('noteReactions'); -db.noteReactions.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.postWatching.renameCollection('noteWatching'); -db.noteWatching.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.posts.renameCollection('notes'); -db.notes.update({}, { - $rename: { - _repost: '_renote', - repostId: 'renoteId', - repostCount: 'renoteCount' - } -}, false, true); - -db.users.update({}, { - $rename: { - postsCount: 'notesCount', - pinnedPostId: 'pinnedNoteId', - latestPost: 'latestNote' - } -}, false, true); diff --git a/tools/migration/nighthike/12.js b/tools/migration/nighthike/12.js deleted file mode 100644 index f4b61e2ee8..0000000000 --- a/tools/migration/nighthike/12.js +++ /dev/null @@ -1,58 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/models/user'); -const { generate } = require('../../../built/crypto_key'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (user) => { - const result = await User.update(user._id, { - $unset: { - account: '' - }, - $set: { - host: null, - hostLower: null, - email: user.account.email, - links: user.account.links, - password: user.account.password, - token: user.account.token, - twitter: user.account.twitter, - line: user.account.line, - profile: user.account.profile, - lastUsedAt: user.account.lastUsedAt, - isBot: user.account.isBot, - isPro: user.account.isPro, - twoFactorSecret: user.account.twoFactorSecret, - twoFactorEnabled: user.account.twoFactorEnabled, - clientSettings: user.account.clientSettings, - settings: user.account.settings, - keypair: user.account.keypair - } - }); - return result.ok === 1; -} - -async function main() { - const count = await User.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await User.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/2.js b/tools/migration/nighthike/2.js deleted file mode 100644 index bb516db5b7..0000000000 --- a/tools/migration/nighthike/2.js +++ /dev/null @@ -1,39 +0,0 @@ -// for Node.js interpret - -const { default: App } = require('../../../built/models/app'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (app) => { - const result = await App.update(app._id, { - $set: { - 'name_id': app.name_id.replace(/\-/g, '_'), - 'name_id_lower': app.name_id_lower.replace(/\-/g, '_') - } - }); - return result.ok === 1; -} - -async function main() { - const count = await App.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await App.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/3.js b/tools/migration/nighthike/3.js deleted file mode 100644 index bde4f773d2..0000000000 --- a/tools/migration/nighthike/3.js +++ /dev/null @@ -1,73 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/models/user'); -const { generate } = require('../../../built/crypto_key'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (user) => { - const result = await User.update(user._id, { - $unset: { - email: '', - links: '', - password: '', - token: '', - twitter: '', - line: '', - profile: '', - last_used_at: '', - is_bot: '', - is_pro: '', - two_factor_secret: '', - two_factor_enabled: '', - client_settings: '', - settings: '' - }, - $set: { - host: null, - host_lower: null, - account: { - email: user.email, - links: user.links, - password: user.password, - token: user.token, - twitter: user.twitter, - line: user.line, - profile: user.profile, - last_used_at: user.last_used_at, - is_bot: user.is_bot, - is_pro: user.is_pro, - two_factor_secret: user.two_factor_secret, - two_factor_enabled: user.two_factor_enabled, - client_settings: user.client_settings, - settings: user.settings, - keypair: generate() - } - } - }); - return result.ok === 1; -} - -async function main() { - const count = await User.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await User.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/4.js b/tools/migration/nighthike/4.js deleted file mode 100644 index 5e12e64055..0000000000 --- a/tools/migration/nighthike/4.js +++ /dev/null @@ -1,262 +0,0 @@ -// このスクリプトを走らせる前か後に notifications コレクションはdropしてください - -db.access_tokens.renameCollection('accessTokens'); -db.accessTokens.update({}, { - $rename: { - created_at: 'createdAt', - app_id: 'appId', - user_id: 'userId', - } -}, false, true); - -db.apps.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - name_id: 'nameId', - name_id_lower: 'nameIdLower', - callback_url: 'callbackUrl', - } -}, false, true); - -db.auth_sessions.renameCollection('authSessions'); -db.authSessions.update({}, { - $rename: { - created_at: 'createdAt', - app_id: 'appId', - user_id: 'userId', - } -}, false, true); - -db.channel_watching.renameCollection('channelWatching'); -db.channelWatching.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - channel_id: 'channelId', - user_id: 'userId', - } -}, false, true); - -db.channels.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - watching_count: 'watchingCount' - } -}, false, true); - -db.drive_files.files.renameCollection('driveFiles.files'); -db.drive_files.chunks.renameCollection('driveFiles.chunks'); -db.driveFiles.files.update({}, { - $rename: { - 'metadata.user_id': 'metadata.userId' - } -}, false, true); -db.driveFiles.files.update({ - 'metadata.folder_id': { $ne: null } -}, { - $rename: { - 'metadata.folder_id': 'metadata.folderId', - } -}, false, true); -db.driveFiles.files.update({ - 'metadata.properties.average_color': { $ne: null } -}, { - $rename: { - 'metadata.properties.average_color': 'metadata.properties.avgColor' - } -}, false, true); - -db.drive_folders.renameCollection('driveFolders'); -db.driveFolders.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - parent_id: 'parentId', - } -}, false, true); - -db.favorites.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId', - } -}, false, true); - -db.following.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - followee_id: 'followeeId', - follower_id: 'followerId', - } -}, false, true); - -db.messaging_histories.renameCollection('messagingHistories'); -db.messagingHistories.update({}, { - $rename: { - updated_at: 'updatedAt', - user_id: 'userId', - partner: 'partnerId', - message: 'messageId', - } -}, false, true); - -db.messaging_messages.renameCollection('messagingMessages'); -db.messagingMessages.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - recipient_id: 'recipientId', - file_id: 'fileId', - is_read: 'isRead' - } -}, false, true); - -db.mute.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - mutee_id: 'muteeId', - muter_id: 'muterId', - } -}, false, true); - -db.othello_games.renameCollection('othelloGames'); -db.othelloGames.update({}, { - $rename: { - created_at: 'createdAt', - started_at: 'startedAt', - is_started: 'isStarted', - is_ended: 'isEnded', - user1_id: 'user1Id', - user2_id: 'user2Id', - user1_accepted: 'user1Accepted', - user2_accepted: 'user2Accepted', - winner_id: 'winnerId', - 'settings.is_llotheo': 'settings.isLlotheo', - 'settings.can_put_everywhere': 'settings.canPutEverywhere', - 'settings.looped_board': 'settings.loopedBoard', - } -}, false, true); - -db.othello_matchings.renameCollection('othelloMatchings'); -db.othelloMatchings.update({}, { - $rename: { - created_at: 'createdAt', - parent_id: 'parentId', - child_id: 'childId' - } -}, false, true); - -db.poll_votes.renameCollection('pollVotes'); -db.pollVotes.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.post_reactions.renameCollection('postReactions'); -db.postReactions.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.post_watching.renameCollection('postWatching'); -db.postWatching.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.posts.update({}, { - $rename: { - created_at: 'createdAt', - channel_id: 'channelId', - user_id: 'userId', - app_id: 'appId', - media_ids: 'mediaIds', - reply_id: 'replyId', - repost_id: 'repostId', - via_mobile: 'viaMobile', - reaction_counts: 'reactionCounts', - replies_count: 'repliesCount', - repost_count: 'repostCount' - } -}, false, true); - -db.posts.update({ - _reply: { $ne: null } -}, { - $rename: { - '_reply.user_id': '_reply.userId', - } -}, false, true); - -db.posts.update({ - _repost: { $ne: null } -}, { - $rename: { - '_repost.user_id': '_repost.userId', - } -}, false, true); - -db.signin.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - } -}, false, true); - -db.sw_subscriptions.renameCollection('swSubscriptions'); -db.swSubscriptions.update({}, { - $rename: { - user_id: 'userId', - } -}, false, true); - -db.users.update({}, { - $unset: { - likes_count: '', - liked_count: '', - latest_post: '', - 'account.twitter.access_token': '', - 'account.twitter.access_token_secret': '', - 'account.twitter.user_id': '', - 'account.twitter.screen_name': '', - 'account.line.user_id': '', - 'account.client_settings.mobile_home': '' - } -}, false, true); - -db.users.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - followers_count: 'followersCount', - following_count: 'followingCount', - posts_count: 'postsCount', - drive_capacity: 'driveCapacity', - username_lower: 'usernameLower', - avatar_id: 'avatarId', - banner_id: 'bannerId', - pinned_post_id: 'pinnedPostId', - is_suspended: 'isSuspended', - host_lower: 'hostLower', - 'account.last_used_at': 'account.lastUsedAt', - 'account.is_bot': 'account.isBot', - 'account.is_pro': 'account.isPro', - 'account.two_factor_secret': 'account.twoFactorSecret', - 'account.two_factor_enabled': 'account.twoFactorEnabled', - 'account.client_settings': 'account.clientSettings' - } -}, false, true); diff --git a/tools/migration/nighthike/5.js b/tools/migration/nighthike/5.js deleted file mode 100644 index 3989ea6301..0000000000 --- a/tools/migration/nighthike/5.js +++ /dev/null @@ -1,49 +0,0 @@ -// for Node.js interpret - -const mongodb = require("../../../built/db/mongodb"); -const Post = mongodb.default.get('posts'); - -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (post) => { - const result = await Post.update(post._id, { - $set: { - 'geo.type': 'Point', - 'geo.coordinates': [post.geo.longitude, post.geo.latitude] - }, - $unset: { - 'geo.longitude': '', - 'geo.latitude': '', - } - }); - return result.ok === 1; -} - -async function main() { - const count = await Post.count({ - 'geo': { $ne: null } - }); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await Post.find({ - 'geo': { $ne: null } - }, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/6.js b/tools/migration/nighthike/6.js deleted file mode 100644 index 27fff2ec19..0000000000 --- a/tools/migration/nighthike/6.js +++ /dev/null @@ -1,13 +0,0 @@ -db.posts.update({ - $or: [{ - mediaIds: null - }, { - mediaIds: { - $exists: false - } - }] -}, { - $set: { - mediaIds: [] - } -}, false, true); diff --git a/tools/migration/nighthike/7.js b/tools/migration/nighthike/7.js deleted file mode 100644 index ed5f1e6b96..0000000000 --- a/tools/migration/nighthike/7.js +++ /dev/null @@ -1,41 +0,0 @@ -// for Node.js interpret - -const mongodb = require("../../../built/db/mongodb"); -const Post = mongodb.default.get('posts'); -const { default: zip } = require('@prezzemolo/zip') -const html = require('../../../built/text/html').default; -const parse = require('../../../built/text/parse').default; - -const migrate = async (post) => { - const result = await Post.update(post._id, { - $set: { - textHtml: post.text ? html(parse(post.text)) : null - } - }); - return result.ok === 1; -} - -async function main() { - const count = await Post.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await Post.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/8.js b/tools/migration/nighthike/8.js deleted file mode 100644 index e4f4482dba..0000000000 --- a/tools/migration/nighthike/8.js +++ /dev/null @@ -1,40 +0,0 @@ -// for Node.js interpret - -const { default: Message } = require('../../../built/models/messaging-message'); -const { default: zip } = require('@prezzemolo/zip') -const html = require('../../../built/text/html').default; -const parse = require('../../../built/text/parse').default; - -const migrate = async (message) => { - const result = await Message.update(message._id, { - $set: { - textHtml: message.text ? html(parse(message.text)) : null - } - }); - return result.ok === 1; -} - -async function main() { - const count = await Message.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await Message.find({}, { - limit: dop, skip: time * dop - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error) diff --git a/tools/migration/nighthike/9.js b/tools/migration/nighthike/9.js deleted file mode 100644 index f4e1ab341e..0000000000 --- a/tools/migration/nighthike/9.js +++ /dev/null @@ -1,93 +0,0 @@ -// for Node.js interpret - -const { default: Following } = require('../../../built/models/following'); -const { default: FollowingLog } = require('../../../built/models/following-log'); -const { default: FollowedLog } = require('../../../built/models/followed-log'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (following) => { - const followingCount = await Following.count({ - followerId: following.followerId, - createdAt: { $lt: following.createdAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowingLog.insert({ - createdAt: following.createdAt, - userId: following.followerId, - count: followingCount + 1 - }); - - const followersCount = await Following.count({ - followeeId: following.followeeId, - createdAt: { $lt: following.createdAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowedLog.insert({ - createdAt: following.createdAt, - userId: following.followeeId, - count: followersCount + 1 - }); - - if (following.deletedAt) { - const followingCount2 = await Following.count({ - followerId: following.followerId, - createdAt: { $lt: following.deletedAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowingLog.insert({ - createdAt: following.deletedAt, - userId: following.followerId, - count: followingCount2 - 1 - }); - - const followersCount2 = await Following.count({ - followeeId: following.followeeId, - createdAt: { $lt: following.deletedAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowedLog.insert({ - createdAt: following.deletedAt, - userId: following.followeeId, - count: followersCount2 - 1 - }); - } - - return true; -} - -async function main() { - const count = await Following.count({}); - - const dop = Number.parseInt(process.argv[2]) || 5 - const idop = ((count - (count % dop)) / dop) + 1 - - return zip( - 1, - async (time) => { - console.log(`${time} / ${idop}`) - const doc = await Following.find({}, { - limit: dop, skip: time * dop, sort: { _id: 1 } - }) - return Promise.all(doc.map(migrate)) - }, - idop - ).then(a => { - const rv = [] - a.forEach(e => rv.push(...e)) - return rv - }) -} - -main().then(console.dir).catch(console.error)