From 72feaecdc1d9bd358396053f6505c46ccb23ef74 Mon Sep 17 00:00:00 2001 From: YUNOCHI Date: Fri, 29 Mar 2024 23:55:02 +0900 Subject: [PATCH] =?UTF-8?q?=EB=85=B8=ED=8A=B8=EB=A5=BC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=ED=95=A0=EB=95=8C=20=ED=83=80=EB=9E=98=EC=9D=98=20?= =?UTF-8?q?=EB=85=B8=ED=8A=B8=EB=93=A4=EA=B9=8C=EC=A7=80=20=EC=9E=AC?= =?UTF-8?q?=EA=B7=80=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1711722198590-no-recursive-delete.js | 14 ++++++++ .../backend/src/core/NoteDeleteService.ts | 34 ------------------- packages/backend/src/models/Note.ts | 2 +- 3 files changed, 15 insertions(+), 35 deletions(-) create mode 100644 packages/backend/migration/1711722198590-no-recursive-delete.js diff --git a/packages/backend/migration/1711722198590-no-recursive-delete.js b/packages/backend/migration/1711722198590-no-recursive-delete.js new file mode 100644 index 000000000000..6fd69826d6f8 --- /dev/null +++ b/packages/backend/migration/1711722198590-no-recursive-delete.js @@ -0,0 +1,14 @@ + +export class NoRecursiveDelete1711722198590 { + name = 'NoRecursiveDelete1711722198590' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "note" DROP CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5"`); + await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5" FOREIGN KEY ("replyId") REFERENCES "note"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "note" DROP CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5"`); + await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5" FOREIGN KEY ("replyId") REFERENCES "note"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + } +} diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index 801ed02e00b3..e0cc33a2de58 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -63,7 +63,6 @@ export class NoteDeleteService { */ async delete(user: { id: MiUser['id']; uri: MiUser['uri']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote, quiet = false, deleter?: MiUser) { const deletedAt = new Date(); - const cascadingNotes = await this.findCascadingNotes(note); if (note.replyId) { await this.notesRepository.decrement({ id: note.replyId }, 'repliesCount', 1); @@ -92,14 +91,6 @@ export class NoteDeleteService { this.deliverToConcerned(user, note, content); } - // also deliever delete activity to cascaded notes - const federatedLocalCascadingNotes = (cascadingNotes).filter(note => !note.localOnly && note.userHost == null); // filter out local-only notes - for (const cascadingNote of federatedLocalCascadingNotes) { - if (!cascadingNote.user) continue; - if (!this.userEntityService.isLocalUser(cascadingNote.user)) continue; - const content = this.apRendererService.addContext(this.apRendererService.renderDelete(this.apRendererService.renderTombstone(`${this.config.url}/notes/${cascadingNote.id}`), cascadingNote.user)); - this.deliverToConcerned(cascadingNote.user, cascadingNote, content); - } //#endregion const meta = await this.metaService.fetch(); @@ -119,9 +110,6 @@ export class NoteDeleteService { } } - for (const cascadingNote of cascadingNotes) { - this.searchService.unindexNote(cascadingNote); - } this.searchService.unindexNote(note); await this.notesRepository.delete({ @@ -141,28 +129,6 @@ export class NoteDeleteService { } } - @bindThis - private async findCascadingNotes(note: MiNote): Promise { - const recursive = async (noteId: string): Promise => { - const query = this.notesRepository.createQueryBuilder('note') - .where('note.replyId = :noteId', { noteId }) - .orWhere(new Brackets(q => { - q.where('note.renoteId = :noteId', { noteId }) - .andWhere('note.text IS NOT NULL'); - })) - .leftJoinAndSelect('note.user', 'user'); - const replies = await query.getMany(); - - return [ - replies, - ...await Promise.all(replies.map(reply => recursive(reply.id))), - ].flat(); - }; - - const cascadingNotes: MiNote[] = await recursive(note.id); - - return cascadingNotes; - } @bindThis private async getMentionedRemoteUsers(note: MiNote) { diff --git a/packages/backend/src/models/Note.ts b/packages/backend/src/models/Note.ts index 9a95c6faab9b..4cd9c92e41d7 100644 --- a/packages/backend/src/models/Note.ts +++ b/packages/backend/src/models/Note.ts @@ -24,7 +24,7 @@ export class MiNote { public replyId: MiNote['id'] | null; @ManyToOne(type => MiNote, { - onDelete: 'CASCADE', + onDelete: 'SET NULL', }) @JoinColumn() public reply: MiNote | null;