diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-15 10:36:22 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-15 10:36:22 +0900 |
| commit | 3f4ee9840560d8c423111f1ab93b2e36218a1314 (patch) | |
| tree | a133afad107362fea5ac00ec8e30704d62a357b9 /packages/backend/src/core | |
| parent | perf(backend): tweak populateMyReaction (diff) | |
| download | misskey-3f4ee9840560d8c423111f1ab93b2e36218a1314.tar.gz misskey-3f4ee9840560d8c423111f1ab93b2e36218a1314.tar.bz2 misskey-3f4ee9840560d8c423111f1ab93b2e36218a1314.zip | |
perf(backend): improve streaming api performance (#12033)
* wip
* Update NoteEntityService.ts
* wip
* wip
* wip
* wip
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/NoteCreateService.ts | 2 | ||||
| -rw-r--r-- | packages/backend/src/core/entities/NoteEntityService.ts | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 4496be3e7d..e12945172f 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -577,7 +577,7 @@ export class NoteCreateService implements OnApplicationShutdown { } // Pack the note - const noteObj = await this.noteEntityService.pack(note); + const noteObj = await this.noteEntityService.pack(note, null, { skipHide: true }); this.globalEventService.publishNotesStream(noteObj); diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 316367f23a..f871ba50a8 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -16,6 +16,7 @@ import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepos import { bindThis } from '@/decorators.js'; import { isNotNull } from '@/misc/is-not-null.js'; import { DebounceLoader } from '@/misc/loader.js'; +import { IdService } from '@/core/IdService.js'; import type { OnModuleInit } from '@nestjs/common'; import type { CustomEmojiService } from '../CustomEmojiService.js'; import type { ReactionService } from '../ReactionService.js'; @@ -28,6 +29,7 @@ export class NoteEntityService implements OnModuleInit { private driveFileEntityService: DriveFileEntityService; private customEmojiService: CustomEmojiService; private reactionService: ReactionService; + private idService: IdService; private noteLoader = new DebounceLoader(this.findNoteOrFail); constructor( @@ -66,6 +68,7 @@ export class NoteEntityService implements OnModuleInit { this.driveFileEntityService = this.moduleRef.get('DriveFileEntityService'); this.customEmojiService = this.moduleRef.get('CustomEmojiService'); this.reactionService = this.moduleRef.get('ReactionService'); + this.idService = this.moduleRef.get('IdService'); } @bindThis @@ -167,11 +170,11 @@ export class NoteEntityService implements OnModuleInit { } @bindThis - private async populateMyReaction(note: MiNote, meId: MiUser['id'], _hint_?: { + public async populateMyReaction(noteId: MiNote['id'], meId: MiUser['id'], _hint_?: { myReactions: Map<MiNote['id'], MiNoteReaction | null>; }) { if (_hint_?.myReactions) { - const reaction = _hint_.myReactions.get(note.id); + const reaction = _hint_.myReactions.get(noteId); if (reaction) { return this.reactionService.convertLegacyReaction(reaction.reaction); } else if (reaction === null) { @@ -181,13 +184,13 @@ export class NoteEntityService implements OnModuleInit { } // パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない - if (note.createdAt.getTime() + 2000 > Date.now()) { + if (this.idService.parse(noteId).date.getTime() + 2000 > Date.now()) { return undefined; } const reaction = await this.noteReactionsRepository.findOneBy({ userId: meId, - noteId: note.id, + noteId: noteId, }); if (reaction) { @@ -355,7 +358,7 @@ export class NoteEntityService implements OnModuleInit { poll: note.hasPoll ? this.populatePoll(note, meId) : undefined, ...(meId ? { - myReaction: this.populateMyReaction(note, meId, options?._hint_), + myReaction: this.populateMyReaction(note.id, meId, options?._hint_), } : {}), } : {}), }); |