Skip to content

Commit 855dc70

Browse files
yunochijbblily
authored andcommitted
노트 삭제시 타래의 노트들까지 삭제하지 않도록 동작변경
1 parent 7b7f8c1 commit 855dc70

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
export class NoRecursiveDelete1711722198590 {
3+
name = 'NoRecursiveDelete1711722198590'
4+
5+
async up(queryRunner) {
6+
await queryRunner.query(`ALTER TABLE "note" DROP CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5"`);
7+
await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5" FOREIGN KEY ("replyId") REFERENCES "note"("id") ON DELETE SET NULL ON UPDATE NO ACTION`);
8+
}
9+
10+
async down(queryRunner) {
11+
await queryRunner.query(`ALTER TABLE "note" DROP CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5"`);
12+
await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_17cb3553c700a4985dff5a30ff5" FOREIGN KEY ("replyId") REFERENCES "note"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
13+
}
14+
}

packages/backend/src/core/NoteDeleteService.ts

-35
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export class NoteDeleteService {
6262
*/
6363
async delete(user: { id: MiUser['id']; uri: MiUser['uri']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote, quiet = false, deleter?: MiUser) {
6464
const deletedAt = new Date();
65-
const cascadingNotes = await this.findCascadingNotes(note);
6665

6766
if (note.replyId) {
6867
await this.notesRepository.decrement({ id: note.replyId }, 'repliesCount', 1);
@@ -91,14 +90,6 @@ export class NoteDeleteService {
9190
this.deliverToConcerned(user, note, content);
9291
}
9392

94-
// also deliver delete activity to cascaded notes
95-
const federatedLocalCascadingNotes = (cascadingNotes).filter(note => !note.localOnly && note.userHost == null); // filter out local-only notes
96-
for (const cascadingNote of federatedLocalCascadingNotes) {
97-
if (!cascadingNote.user) continue;
98-
if (!this.userEntityService.isLocalUser(cascadingNote.user)) continue;
99-
const content = this.apRendererService.addContext(this.apRendererService.renderDelete(this.apRendererService.renderTombstone(`${this.config.url}/notes/${cascadingNote.id}`), cascadingNote.user));
100-
this.deliverToConcerned(cascadingNote.user, cascadingNote, content);
101-
}
10293
//#endregion
10394

10495
this.notesChart.update(note, false);
@@ -118,9 +109,6 @@ export class NoteDeleteService {
118109
}
119110
}
120111

121-
for (const cascadingNote of cascadingNotes) {
122-
this.searchService.unindexNote(cascadingNote);
123-
}
124112
this.searchService.unindexNote(note);
125113

126114
await this.notesRepository.delete({
@@ -140,29 +128,6 @@ export class NoteDeleteService {
140128
}
141129
}
142130

143-
@bindThis
144-
private async findCascadingNotes(note: MiNote): Promise<MiNote[]> {
145-
const recursive = async (noteId: string): Promise<MiNote[]> => {
146-
const query = this.notesRepository.createQueryBuilder('note')
147-
.where('note.replyId = :noteId', { noteId })
148-
.orWhere(new Brackets(q => {
149-
q.where('note.renoteId = :noteId', { noteId })
150-
.andWhere('note.text IS NOT NULL');
151-
}))
152-
.leftJoinAndSelect('note.user', 'user');
153-
const replies = await query.getMany();
154-
155-
return [
156-
replies,
157-
...await Promise.all(replies.map(reply => recursive(reply.id))),
158-
].flat();
159-
};
160-
161-
const cascadingNotes: MiNote[] = await recursive(note.id);
162-
163-
return cascadingNotes;
164-
}
165-
166131
@bindThis
167132
private async getMentionedRemoteUsers(note: MiNote) {
168133
const where = [] as any[];

packages/backend/src/models/Note.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class MiNote {
2424
public replyId: MiNote['id'] | null;
2525

2626
@ManyToOne(type => MiNote, {
27-
onDelete: 'CASCADE',
27+
onDelete: 'SET NULL',
2828
})
2929
@JoinColumn()
3030
public reply: MiNote | null;

0 commit comments

Comments
 (0)