From 588fcbe69e3ef474c7fc79e184c112a98e4dae67 Mon Sep 17 00:00:00 2001 From: yupix Date: Tue, 26 Sep 2023 00:45:25 +0000 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E8=A1=8C=E7=94=A8=E3=82=B9?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88=E3=81=AE=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/migration/drive.ts | 26 +++++++++++++++++--------- src/migration/hashtag.ts | 2 +- src/migration/note.ts | 9 ++++++--- src/migration/user.ts | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/migration/drive.ts b/src/migration/drive.ts index 5613961db..b34b19a3e 100644 --- a/src/migration/drive.ts +++ b/src/migration/drive.ts @@ -11,15 +11,15 @@ import { createUser } from "./user"; import { LRUCache } from "lru-cache"; const driveFileCache = new LRUCache({ - max: 1000 -}) + max: 1000, +}); export async function migrateDriveFile( driveFileId: string, - useFile?: DriveFile, + useFile?: DriveFile ) { - const cacheKey = `migrateDriveFile${driveFileId}` - const cacheResult = driveFileCache.get(cacheKey) + const cacheKey = `migrateDriveFile${driveFileId}`; + const cacheResult = driveFileCache.get(cacheKey); if (cacheResult) return cacheResult; const originalDb = getConnection(); @@ -46,8 +46,9 @@ export async function migrateDriveFile( file = result; } - if (file.folderId) await migrateDriveFolder(originalDb, nextDb, file.folderId); - if (file.userId) await createUser({userId: file.userId}) // ユーザーその物しか作成しない。migrateUsersであとでその他の情報は作成される + if (file.folderId) + await migrateDriveFolder(originalDb, nextDb, file.folderId); + if (file.userId) await createUser({ userId: file.userId }); // ユーザーその物しか作成しない。migrateUsersであとでその他の情報は作成される const createdDriveFile = await driveFileRepository.save({ id: file.id, @@ -75,7 +76,7 @@ export async function migrateDriveFile( isLink: file.isLink, }); driveFileCache.set(cacheKey, createdDriveFile); - return createdDriveFile + return createdDriveFile; } export async function migrateDriveFiles( @@ -86,9 +87,16 @@ export async function migrateDriveFiles( const pagination = createPagination(originalDb, DriveFile, { where: { userId }, }); + const driveFileRepository = nextDb.getRepository(v13DriveFile); while (true) { const files = await pagination.next(); for (const file of files) { + const checkExists = await driveFileRepository.findOne({ + where: { id: file.id }, + }); + if (checkExists) { + continue; + } driveFileQueue.add({ driveFileId: file.id, useFile: file }); } if (files.length === 0) break; // 100以下になったら止める @@ -105,7 +113,7 @@ export async function migrateDriveFolder( const driveFolderRepository = nextDb.getRepository(v13DriveFolder); async function save(folder: DriveFolder) { - if (folder.userId) await createUser({userId: folder.userId}) + if (folder.userId) await createUser({ userId: folder.userId }); return await driveFolderRepository.save({ createdAt: folder.createdAt, id: folder.id, diff --git a/src/migration/hashtag.ts b/src/migration/hashtag.ts index f401171c0..dcdc0e127 100644 --- a/src/migration/hashtag.ts +++ b/src/migration/hashtag.ts @@ -63,7 +63,7 @@ export async function migrateHashtags(originalDb: Connection, nextDb: Connection count++ const checkExists = await hashtagRepository.findOne({where: {id: hashtag.id}}); if (checkExists) { - logger.info(`Hashtag: ${hashtag.id} は移行済みです ${count}`) + // logger.info(`Hashtag: ${hashtag.id} は移行済みです ${count}`) continue } hashtagQueue.add({hashtagId: hashtag.id, useHashtag: hashtag}) diff --git a/src/migration/note.ts b/src/migration/note.ts index 6950ce20e..d6a041300 100644 --- a/src/migration/note.ts +++ b/src/migration/note.ts @@ -50,6 +50,9 @@ export async function migrateNote(noteId: string, useNote?: Note) { await migrateNoteReactions(originalDb, nextDb, note.id); await migrateNoteUnreads(originalDb, nextDb, note.id); await migrateNoteFavorites(note.id); + if (await noteQueue.getCompletedCount() > 1000) { + await noteQueue.clean(0, 'completed') + } logger.succ(`Note: ${note.id} の移行が完了しました`); } @@ -91,8 +94,8 @@ export async function migrateNote(noteId: string, useNote?: Note) { } - const checkExists = await noteRepository.findOne(note.id); // 既にノートが移行済みか確認 - if (checkExists) return; // 移行済みならスキップする + // const checkExists = await noteRepository.findOne(note.id); // 既にノートが移行済みか確認 + // if (checkExists) return; // 移行済みならスキップする if (note.replyId) await checkReply(note.replyId); // リプライが既に登録されてるか確認し、無いなら再帰的に作成する if (note.renoteId) await checkRenoteId(note.renoteId); // renoteが既に登録されてるか確認し、無いなら再帰的に作成する @@ -113,7 +116,7 @@ export async function migrateNotes( for (const note of notes) { const checkExists = await noteRepository.findOne({where: {id: note.id}}) if (checkExists) { - logger.info(`Note: ${note.id} は移行済みです`) + // logger.info(`Note: ${note.id} は移行済みです`) continue } noteQueue.add({ noteId: note.id, note }); diff --git a/src/migration/user.ts b/src/migration/user.ts index 407e2b9a5..52bed4320 100644 --- a/src/migration/user.ts +++ b/src/migration/user.ts @@ -40,7 +40,7 @@ export async function createUser(options: {userId: string, useUser?: User}) { if (checkExists) { resultUser = checkExists; - logger.info(`User: ${options.userId} は既に移行済みです`); + // logger.info(`User: ${options.userId} は既に移行済みです`); } else { resultUser = await userRepository.save({ id: user.id,