Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/backend/src/core/NoteDeleteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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(async reply => await recursive(reply.id))),
okayurisotto marked this conversation as resolved.
Show resolved Hide resolved
].flat();
};
await recursive(note.id);

const cascadingNotes: Note[] = await recursive(note.id);

return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users
}
Expand Down