diff options
| author | okayurisotto <okayurisotto@proton.me> | 2023-07-06 11:25:46 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-06 11:25:46 +0900 |
| commit | 4a7da723b3327c5905b95e3a01cd4b43dd5e9ad9 (patch) | |
| tree | f5903fe05996cfb1a9a69eeba05f0dfd1a728fa3 /packages/backend/src/core/NoteDeleteService.ts | |
| parent | エスケープせずにDescriptionを出力、Update info-card.pug (#11108) (diff) | |
| download | sharkey-4a7da723b3327c5905b95e3a01cd4b43dd5e9ad9.tar.gz sharkey-4a7da723b3327c5905b95e3a01cd4b43dd5e9ad9.tar.bz2 sharkey-4a7da723b3327c5905b95e3a01cd4b43dd5e9ad9.zip | |
refactor(backend): ノート削除時の`findCascadingNotes`の処理を整理 (#11131)
* refactor(backend): ノート削除時の`findCascadingNotes`の処理を整理
* cleanup: unneeded async await
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
---------
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/core/NoteDeleteService.ts')
| -rw-r--r-- | packages/backend/src/core/NoteDeleteService.ts | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index dd878f7bba..3612ac806f 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -121,10 +121,8 @@ export class NoteDeleteService { } @bindThis - private async findCascadingNotes(note: Note) { - const cascadingNotes: Note[] = []; - - const recursive = async (noteId: string) => { + private async findCascadingNotes(note: Note): Promise<Note[]> { + const recursive = async (noteId: string): Promise<Note[]> => { const query = this.notesRepository.createQueryBuilder('note') .where('note.replyId = :noteId', { noteId }) .orWhere(new Brackets(q => { @@ -133,12 +131,14 @@ export class NoteDeleteService { })) .leftJoinAndSelect('note.user', 'user'); const replies = await query.getMany(); - for (const reply of replies) { - cascadingNotes.push(reply); - await recursive(reply.id); - } + + return [ + replies, + ...await Promise.all(replies.map(reply => recursive(reply.id))), + ].flat(); }; - await recursive(note.id); + + const cascadingNotes: Note[] = await recursive(note.id); return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users } |