Skip to content
Snippets Groups Projects
Unverified Commit 4a7da723 authored by okayurisotto's avatar okayurisotto Committed by GitHub
Browse files

refactor(backend): ノート削除時の`findCascadingNotes`の処理を整理 (#11131)


* refactor(backend): ノート削除時の`findCascadingNotes`の処理を整理

* cleanup: unneeded async await

Co-authored-by: default avatarsyuilo <Syuilotan@yahoo.co.jp>

---------

Co-authored-by: default avatarsyuilo <Syuilotan@yahoo.co.jp>
parent d2f8ed95
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment