mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 22:39:33 +09:00
fix(queue): アカウント削除が終わらない問題を修正 (MisskeyIO#526)
cheery-picked from tanukey-dev/tanukey@7ddecf1eab Co-authored-by: tar_bin <tar.bin.master@gmail.com>
This commit is contained in:
parent
142a906dec
commit
5c019eec04
@ -4,13 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { MoreThan } from 'typeorm';
|
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { DriveFilesRepository, NotesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
|
import type { DriveFilesRepository, NotesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
|
||||||
import type Logger from '@/logger.js';
|
import type Logger from '@/logger.js';
|
||||||
import { DriveService } from '@/core/DriveService.js';
|
import { DriveService } from '@/core/DriveService.js';
|
||||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
import type { MiUser } from '@/models/User.js';
|
||||||
import type { MiNote } from '@/models/Note.js';
|
|
||||||
import { EmailService } from '@/core/EmailService.js';
|
import { EmailService } from '@/core/EmailService.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { SearchService } from '@/core/SearchService.js';
|
import { SearchService } from '@/core/SearchService.js';
|
||||||
@ -43,36 +41,19 @@ export class DeleteAccountProcessorService {
|
|||||||
this.logger = this.queueLoggerService.logger.createSubLogger('delete-account');
|
this.logger = this.queueLoggerService.logger.createSubLogger('delete-account');
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
private async deleteNotes(user: MiUser) {
|
||||||
public async process(job: Bull.Job<DbUserDeleteJobData>): Promise<string | void> {
|
|
||||||
this.logger.info(`Deleting account of ${job.data.user.id} ...`);
|
|
||||||
|
|
||||||
const user = await this.usersRepository.findOneBy({ id: job.data.user.id });
|
|
||||||
if (user == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Delete notes
|
|
||||||
let cursor: MiNote['id'] | null = null;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const notes = await this.notesRepository.find({
|
const notes = await this.notesRepository.find({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
...(cursor ? { id: MoreThan(cursor) } : {}),
|
|
||||||
},
|
},
|
||||||
take: 100,
|
take: 100,
|
||||||
order: {
|
});
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
}) as MiNote[];
|
|
||||||
|
|
||||||
if (notes.length === 0) {
|
if (notes.length === 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = notes[notes.length - 1].id;
|
|
||||||
|
|
||||||
await this.notesRepository.delete(notes.map(note => note.id));
|
await this.notesRepository.delete(notes.map(note => note.id));
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
@ -83,27 +64,19 @@ export class DeleteAccountProcessorService {
|
|||||||
this.logger.succ('All of notes deleted');
|
this.logger.succ('All of notes deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Delete files
|
private async deleteFiles(user: MiUser) {
|
||||||
let cursor: MiDriveFile['id'] | null = null;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const files = await this.driveFilesRepository.find({
|
const files = await this.driveFilesRepository.find({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
...(cursor ? { id: MoreThan(cursor) } : {}),
|
|
||||||
},
|
},
|
||||||
take: 10,
|
take: 10,
|
||||||
order: {
|
});
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
}) as MiDriveFile[];
|
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = files[files.length - 1].id;
|
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
await this.driveService.deleteFileSync(file);
|
await this.driveService.deleteFileSync(file);
|
||||||
}
|
}
|
||||||
@ -112,10 +85,24 @@ export class DeleteAccountProcessorService {
|
|||||||
this.logger.succ('All of files deleted');
|
this.logger.succ('All of files deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
public async process(job: Bull.Job<DbUserDeleteJobData>): Promise<string | void> {
|
||||||
|
this.logger.info(`Deleting account of ${job.data.user.id} ...`);
|
||||||
|
|
||||||
|
const user = await this.usersRepository.findOneBy({ id: job.data.user.id });
|
||||||
|
if (user == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.deleteNotes(user),
|
||||||
|
this.deleteFiles(user),
|
||||||
|
]);
|
||||||
|
|
||||||
{ // Send email notification
|
{ // Send email notification
|
||||||
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
||||||
if (profile.email && profile.emailVerified) {
|
if (profile.email && profile.emailVerified) {
|
||||||
this.emailService.sendEmail(profile.email, 'Account deleted',
|
await this.emailService.sendEmail(profile.email, 'Account deleted',
|
||||||
'Your account has been deleted.',
|
'Your account has been deleted.',
|
||||||
'Your account has been deleted.');
|
'Your account has been deleted.');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user