mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 02:23:08 +02:00
upd: delete reactions properly in the DB
Fixes https://github.com/misskey-dev/misskey/issues/11906
This commit is contained in:
parent
d748e6cfbd
commit
fe4345d191
1 changed files with 38 additions and 1 deletions
|
@ -6,17 +6,19 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { MoreThan } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { DriveFilesRepository, NotesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
|
||||
import type { DriveFilesRepository, NoteReactionsRepository, NotesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { DriveService } from '@/core/DriveService.js';
|
||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||
import type { MiNote } from '@/models/Note.js';
|
||||
import type { MiNoteReaction } from '@/models/NoteReaction.js';
|
||||
import { EmailService } from '@/core/EmailService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { SearchService } from '@/core/SearchService.js';
|
||||
import { QueueLoggerService } from '../QueueLoggerService.js';
|
||||
import type * as Bull from 'bullmq';
|
||||
import type { DbUserDeleteJobData } from '../types.js';
|
||||
import { ReactionService } from '@/core/ReactionService.js';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteAccountProcessorService {
|
||||
|
@ -35,10 +37,14 @@ export class DeleteAccountProcessorService {
|
|||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
@Inject(DI.noteReactionsRepository)
|
||||
private noteReactionsRepository: NoteReactionsRepository,
|
||||
|
||||
private driveService: DriveService,
|
||||
private emailService: EmailService,
|
||||
private queueLoggerService: QueueLoggerService,
|
||||
private searchService: SearchService,
|
||||
private reactionService: ReactionService,
|
||||
) {
|
||||
this.logger = this.queueLoggerService.logger.createSubLogger('delete-account');
|
||||
}
|
||||
|
@ -83,6 +89,37 @@ export class DeleteAccountProcessorService {
|
|||
this.logger.succ('All of notes deleted');
|
||||
}
|
||||
|
||||
{ // Delete reactions
|
||||
let cursor: MiNoteReaction['id'] | null = null;
|
||||
|
||||
while (true) {
|
||||
const reactions = await this.noteReactionsRepository.find({
|
||||
where: {
|
||||
userId: user.id,
|
||||
...(cursor ? { id: MoreThan(cursor) } : {}),
|
||||
},
|
||||
take: 100,
|
||||
order: {
|
||||
id: 1,
|
||||
},
|
||||
}) as MiNoteReaction[];
|
||||
|
||||
if (reactions.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
cursor = reactions.at(-1)?.id ?? null;
|
||||
|
||||
for (const reaction of reactions) {
|
||||
const note = await this.notesRepository.findOneBy({ id: reaction.noteId }) as MiNote;
|
||||
|
||||
await this.reactionService.delete(user, note);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.succ('All reactions have been deleted');
|
||||
}
|
||||
|
||||
{ // Delete files
|
||||
let cursor: MiDriveFile['id'] | null = null;
|
||||
|
||||
|
|
Loading…
Reference in a new issue