Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
feat: ノートのキューが100万以下の場合にのみジョブを追加できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Sep 29, 2023
1 parent f47a1c0 commit 7a861d8
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/migration/userAfterHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ import { migrateDriveFiles, migrateDriveFolders } from "./drive";
import { getConnection } from "typeorm";
import { migratePasswordResetRequests } from "./PassworResetRequest";
import { migrateAuthSessions } from "./AuthSession";
import { userAfterHookQueue } from "./jobqueue";
import { noteQueue, userAfterHookQueue } from "./jobqueue";
import { logger } from "./common";

export async function userAfterHook(user: User) {
const originalDb = getConnection();
const nextDb = getConnection("nextDb");
await migrateDriveFolders(originalDb, nextDb, user.id); // そんなにフォルダがあるなんてこと無いだろうから、キューにする必要はない?
await migrateDriveFiles(originalDb, nextDb, user.id);
await migrateNotes(originalDb, nextDb, user.id);
const originalDb = getConnection();
const nextDb = getConnection("nextDb");
await migrateDriveFolders(originalDb, nextDb, user.id); // そんなにフォルダがあるなんてこと無いだろうから、キューにする必要はない?
await migrateDriveFiles(originalDb, nextDb, user.id);
while (true) {
if ((await noteQueue.getCompletedCount()) < 1000000) {
await migrateNotes(originalDb, nextDb, user.id);
break
} else {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}

await migrateUserKeypair(originalDb, nextDb, user.id);
await migrateUserPublickey(originalDb, nextDb, user.id);
await migrateUserSecurityKeys(originalDb, nextDb, user.id);
await migrateBlockings(originalDb, nextDb, user.id);
await migrateMutings(originalDb, nextDb, user.id);
await migrateFollowings(originalDb, nextDb, user.id);
await migrateSignins(originalDb, nextDb, user.id);
await migratePasswordResetRequests(originalDb, nextDb, user.id);
await migrateAuthSessions(originalDb, nextDb, user.id);
await migrateUserKeypair(originalDb, nextDb, user.id);
await migrateUserPublickey(originalDb, nextDb, user.id);
await migrateUserSecurityKeys(originalDb, nextDb, user.id);
await migrateBlockings(originalDb, nextDb, user.id);
await migrateMutings(originalDb, nextDb, user.id);
await migrateFollowings(originalDb, nextDb, user.id);
await migrateSignins(originalDb, nextDb, user.id);
await migratePasswordResetRequests(originalDb, nextDb, user.id);
await migrateAuthSessions(originalDb, nextDb, user.id);

if (await userAfterHookQueue.getCompletedCount() > 1000) {
await userAfterHookQueue.clean(0, "completed");
}
logger.succ(`UserAfterHook: ${user.id} の処理が完了しました`);
if ((await userAfterHookQueue.getCompletedCount()) > 1000) {
await userAfterHookQueue.clean(0, "completed");
}
logger.succ(`UserAfterHook: ${user.id} の処理が完了しました`);
}

0 comments on commit 7a861d8

Please sign in to comment.