This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
forked from mei23/misskey-v11
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(server): Use job queue for account delete (#525)
* enhance(server): Use job queue for account delete (#7668) * enhance(server): Use job queue for account delete Fix #5336 * ジョブをひとつに * remove done call * clean up * add User.isDeleted * コミット忘れ * Update 1629512953000-user-is-deleted.ts * show dialog * lint * Update 1629512953000-user-is-deleted.ts * chore: tsconfigの整理 * fix: error * chore: 調整 * fix: インポート * chore: tune * chore: tune * chore: tune * feat: delete actor * refactor: unused * docs: update
- Loading branch information
1 parent
a385f9d
commit 543c8d2
Showing
14 changed files
with
175 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class isUserDeleted1629512953000 implements MigrationInterface { | ||
name = 'isUserDeleted1629512953000' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "user" ADD "isDeleted" boolean NOT NULL DEFAULT false`); | ||
await queryRunner.query(`COMMENT ON COLUMN "user"."isDeleted" IS 'Whether the User is deleted.'`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isDeleted"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as Bull from 'bull'; | ||
import { queueLogger } from '../../logger'; | ||
import { DriveFiles, Notes, Users } from '../../../models/index'; | ||
import { DbUserJobData } from '../../type'; | ||
import { Note } from '../../../models/entities/note'; | ||
import { DriveFile } from '../../../models/entities/drive-file'; | ||
import { MoreThan } from 'typeorm'; | ||
import { deleteFileSync } from '../../../services/drive/delete-file'; | ||
|
||
const logger = queueLogger.createSubLogger('delete-account'); | ||
|
||
export async function deleteAccount(job: Bull.Job<DbUserJobData>): Promise<string | void> { | ||
logger.info(`Deleting account of ${job.data.user.id} ...`); | ||
|
||
const user = await Users.findOne(job.data.user.id); | ||
if (user == null) { | ||
return; | ||
} | ||
|
||
{ // Delete notes | ||
let cursor: Note['id'] | null = null; | ||
|
||
while (true) { | ||
const notes = await Notes.find({ | ||
where: { | ||
userId: user.id, | ||
...(cursor ? { id: MoreThan(cursor) } : {}) | ||
}, | ||
take: 100, | ||
order: { | ||
id: 1 | ||
} | ||
}); | ||
|
||
if (notes.length === 0) { | ||
break; | ||
} | ||
|
||
cursor = notes[notes.length - 1].id; | ||
|
||
await Notes.delete(notes.map(note => note.id)); | ||
} | ||
|
||
logger.succ(`All of notes deleted`); | ||
} | ||
|
||
{ // Delete files | ||
let cursor: DriveFile['id'] | null = null; | ||
|
||
while (true) { | ||
const files = await DriveFiles.find({ | ||
where: { | ||
userId: user.id, | ||
...(cursor ? { id: MoreThan(cursor) } : {}) | ||
}, | ||
take: 10, | ||
order: { | ||
id: 1 | ||
} | ||
}); | ||
|
||
if (files.length === 0) { | ||
break; | ||
} | ||
|
||
cursor = files[files.length - 1].id; | ||
|
||
for (const file of files) { | ||
await deleteFileSync(file); | ||
} | ||
} | ||
|
||
logger.succ(`All of files deleted`); | ||
} | ||
|
||
await Users.delete(job.data.user.id); | ||
|
||
return 'Account deleted'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { apLogger } from '../../logger'; | ||
import { createDeleteAccountJob } from '../../../../queue'; | ||
import { IRemoteUser } from '../../../../models/entities/user'; | ||
import { Users } from '../../../../models'; | ||
|
||
const logger = apLogger; | ||
|
||
export async function deleteActor(actor: IRemoteUser, uri: string): Promise<string> { | ||
logger.info(`Deleting the Actor: ${uri}`); | ||
|
||
if (actor.uri !== uri) { | ||
return `skip: delete actor ${actor.uri} !== ${uri}`; | ||
} | ||
|
||
if (actor.isDeleted) { | ||
logger.info(`skip: already deleted`); | ||
} | ||
|
||
const job = await createDeleteAccountJob(actor); | ||
|
||
await Users.update(actor.id, { | ||
isDeleted: true, | ||
}); | ||
|
||
return `ok: queued ${job.name} ${job.id}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters