Skip to content

Commit

Permalink
perf(backend): reduce db query
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Apr 6, 2023
1 parent a0d5e24 commit de9d136
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export class NoteEntityService implements OnModuleInit {
// 実装上抜けがあるだけかもしれないので、「ヒントに含まれてなかったら(=undefinedなら)return」のようにはしない
}

// パフォーマンスのためノートが作成されてから1秒以上経っていない場合はリアクションを取得しない
if (note.createdAt.getTime() + 1000 > Date.now()) {
return undefined;
}

const reaction = await this.noteReactionsRepository.findOneBy({
userId: meId,
noteId: note.id,
Expand Down Expand Up @@ -395,7 +400,8 @@ export class NoteEntityService implements OnModuleInit {
const myReactionsMap = new Map<Note['id'], NoteReaction | null>();
if (meId) {
const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);
const targets = [...notes.map(n => n.id), ...renoteIds];
// パフォーマンスのためノートが作成されてから1秒以上経っていない場合はリアクションを取得しない
const targets = [...notes.filter(n => n.createdAt.getTime() + 1000 < Date.now()).map(n => n.id), ...renoteIds];
const myReactions = await this.noteReactionsRepository.findBy({
userId: meId,
noteId: In(targets),
Expand Down

0 comments on commit de9d136

Please sign in to comment.