From fcc48640800f6dcf4eb31d438609d00059b654bd Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 19 Oct 2023 07:56:25 +0900 Subject: [PATCH] perf(backend): reduce needless populateMyReaction calls --- packages/backend/src/core/entities/NoteEntityService.ts | 2 +- packages/backend/src/server/api/stream/channels/channel.ts | 6 ++++-- .../src/server/api/stream/channels/global-timeline.ts | 6 ++++-- packages/backend/src/server/api/stream/channels/hashtag.ts | 6 ++++-- .../backend/src/server/api/stream/channels/home-timeline.ts | 6 ++++-- .../src/server/api/stream/channels/hybrid-timeline.ts | 6 ++++-- .../src/server/api/stream/channels/local-timeline.ts | 6 ++++-- .../backend/src/server/api/stream/channels/user-list.ts | 6 ++++-- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 7cb7e4b91..9a59da434 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -357,7 +357,7 @@ export class NoteEntityService implements OnModuleInit { poll: note.hasPoll ? this.populatePoll(note, meId) : undefined, - ...(meId ? { + ...(meId && Object.keys(note.reactions).length > 0 ? { myReaction: this.populateMyReaction(note.id, meId, options?._hint_), } : {}), } : {}), diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index e4c34e00c..251350dda 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -46,8 +46,10 @@ class ChannelChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index c499d1787..9c623abf7 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -72,8 +72,10 @@ class GlobalTimelineChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/hashtag.ts b/packages/backend/src/server/api/stream/channels/hashtag.ts index 2cfe9572d..247145d8c 100644 --- a/packages/backend/src/server/api/stream/channels/hashtag.ts +++ b/packages/backend/src/server/api/stream/channels/hashtag.ts @@ -51,8 +51,10 @@ class HashtagChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index 3ccf4af66..eed5c699d 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -74,8 +74,10 @@ class HomeTimelineChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 760fab60a..d9b5cafc8 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -88,8 +88,10 @@ class HybridTimelineChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index a21104113..2424b468d 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -71,8 +71,10 @@ class LocalTimelineChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts index b73cedaa8..c3b4c9d74 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -103,8 +103,10 @@ class UserListChannel extends Channel { if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return; if (this.user && note.renoteId && !note.text) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); - note.renote!.myReaction = myRenoteReaction; + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id); + note.renote!.myReaction = myRenoteReaction; + } } this.connection.cacheNote(note);