Skip to content

Commit

Permalink
Debounce notes.findOneOrFail in NoteEntityService.pack
Browse files Browse the repository at this point in the history
  • Loading branch information
KOBA789 committed Oct 7, 2023
1 parent 6e46c97 commit b70ae7a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
} from '@/models/index.js';
import { bindThis } from '@/decorators.js';
import { isNotNull } from '@/misc/is-not-null.js';
import { DebounceLoader } from '@/misc/loader.js';
import type { OnModuleInit } from '@nestjs/common';
import type { CustomEmojiService } from '../CustomEmojiService.js';
import type { ReactionService } from '../ReactionService.js';
Expand All @@ -38,6 +39,7 @@ export class NoteEntityService implements OnModuleInit {
private driveFileEntityService: DriveFileEntityService;
private customEmojiService: CustomEmojiService;
private reactionService: ReactionService;
private noteLoader = new DebounceLoader(this.findNoteOrFail);

constructor(
private moduleRef: ModuleRef,
Expand Down Expand Up @@ -304,7 +306,7 @@ export class NoteEntityService implements OnModuleInit {
}, options);

const meId = me ? me.id : null;
const note = typeof src === 'object' ? src : await this.notesRepository.findOneOrFail({ where: { id: src }, relations: ['user'] });
const note = typeof src === 'object' ? src : await this.noteLoader.load(src);
const host = note.userHost;

let text = note.text;
Expand Down Expand Up @@ -483,4 +485,12 @@ export class NoteEntityService implements OnModuleInit {

return await query.getCount();
}

@bindThis
private async findNoteOrFail(id: string): Promise<MiNote> {
return await this.notesRepository.findOneOrFail({
where: { id },
relations: ["user"],
});
}
}

0 comments on commit b70ae7a

Please sign in to comment.