forked from mirror/misskey
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>
This commit is contained in:
parent
d2f8ed95aa
commit
4a7da723b3
@ -121,10 +121,8 @@ export class NoteDeleteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async findCascadingNotes(note: Note) {
|
private async findCascadingNotes(note: Note): Promise<Note[]> {
|
||||||
const cascadingNotes: Note[] = [];
|
const recursive = async (noteId: string): Promise<Note[]> => {
|
||||||
|
|
||||||
const recursive = async (noteId: string) => {
|
|
||||||
const query = this.notesRepository.createQueryBuilder('note')
|
const query = this.notesRepository.createQueryBuilder('note')
|
||||||
.where('note.replyId = :noteId', { noteId })
|
.where('note.replyId = :noteId', { noteId })
|
||||||
.orWhere(new Brackets(q => {
|
.orWhere(new Brackets(q => {
|
||||||
@ -133,12 +131,14 @@ export class NoteDeleteService {
|
|||||||
}))
|
}))
|
||||||
.leftJoinAndSelect('note.user', 'user');
|
.leftJoinAndSelect('note.user', 'user');
|
||||||
const replies = await query.getMany();
|
const replies = await query.getMany();
|
||||||
for (const reply of replies) {
|
|
||||||
cascadingNotes.push(reply);
|
return [
|
||||||
await recursive(reply.id);
|
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
|
return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user