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

@ -8,7 +8,7 @@ import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '.
import { toString } from '../../mfm/to-string';
import { parse } from '../../mfm/parse';
import { NoteReaction } from '../entities/note-reaction';
import { populateEmojis } from '../../misc/populate-emojis';
import { aggregateNoteEmojis, populateEmojis, prefetchEmojis } from '../../misc/populate-emojis';
export type PackedNote = SchemaType<typeof packedNoteSchema>;
@ -259,6 +259,8 @@ export class NoteRepository extends Repository<Note> {
}
}
await prefetchEmojis(aggregateNoteEmojis(notes));
return await Promise.all(notes.map(n => this.pack(n, me, {
...options,
_hint_: {

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