perf(server): Reduce database query

This commit is contained in:
syuilo
2021-03-22 12:41:33 +09:00
parent 1f0abef084
commit 8f41dfec2e
3 changed files with 53 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import { SchemaType } from '../../misc/schema';
import { Note } from '../entities/note';
import { NoteReaction } from '../entities/note-reaction';
import { User } from '../entities/user';
import { aggregateNoteEmojis, prefetchEmojis } from '../../misc/populate-emojis';
export type PackedNotification = SchemaType<typeof packedNotificationSchema>;
@@ -98,6 +99,8 @@ export class NotificationRepository extends Repository<Notification> {
myReactionsMap.set(target, myReactions.find(reaction => reaction.noteId === target) || null);
}
await prefetchEmojis(aggregateNoteEmojis(notes));
return await Promise.all(notifications.map(x => this.pack(x, {
_hintForEachNotes_: {
myReactions: myReactionsMap