From c4fafbdca7076d7be3c34aa77608a4a391c1784d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=82=8F=E3=82=8F=E3=82=8F=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:35:08 +0900 Subject: [PATCH] =?UTF-8?q?perf(stream):=20=E5=BF=85=E8=A6=81=E3=81=AE?= =?UTF-8?q?=E3=81=AA=E3=81=84=E6=97=A2=E8=AA=AD=E5=87=A6=E7=90=86=E3=81=AE?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=8C=E7=99=BA?= =?UTF-8?q?=E7=94=9F=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(MisskeyIO#907)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/server/api/stream/channels/antenna.ts | 5 ++++- .../src/server/api/stream/channels/channel.ts | 5 ++++- .../server/api/stream/channels/global-timeline.ts | 5 ++++- .../src/server/api/stream/channels/hashtag.ts | 4 +++- .../src/server/api/stream/channels/home-timeline.ts | 5 ++++- .../server/api/stream/channels/hybrid-timeline.ts | 5 ++++- .../src/server/api/stream/channels/local-timeline.ts | 5 ++++- .../backend/src/server/api/stream/channels/main.ts | 12 ++++++++++-- .../src/server/api/stream/channels/role-timeline.ts | 5 ++++- .../src/server/api/stream/channels/user-list.ts | 5 ++++- packages/frontend/src/scripts/use-note-capture.ts | 7 +++++-- 11 files changed, 50 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/server/api/stream/channels/antenna.ts b/packages/backend/src/server/api/stream/channels/antenna.ts index ff05359b5..f47a644de 100644 --- a/packages/backend/src/server/api/stream/channels/antenna.ts +++ b/packages/backend/src/server/api/stream/channels/antenna.ts @@ -51,6 +51,10 @@ class AntennaChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -59,7 +63,6 @@ class AntennaChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', note); } } else { diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index 96ada8c97..7ebc2ed56 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -57,6 +57,10 @@ class ChannelChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -65,7 +69,6 @@ class ChannelChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', 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 581618740..371449cfd 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -87,6 +87,10 @@ class GlobalTimelineChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -95,7 +99,6 @@ class GlobalTimelineChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', note); } } diff --git a/packages/backend/src/server/api/stream/channels/hashtag.ts b/packages/backend/src/server/api/stream/channels/hashtag.ts index c7384fdf9..0dbd70b99 100644 --- a/packages/backend/src/server/api/stream/channels/hashtag.ts +++ b/packages/backend/src/server/api/stream/channels/hashtag.ts @@ -60,7 +60,9 @@ class HashtagChannel extends Channel { } } - this.connection.cacheNote(note); + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } this.send('note', 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 34890854c..7b38cb59c 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -91,6 +91,10 @@ class HomeTimelineChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -99,7 +103,6 @@ class HomeTimelineChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', 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 47d534aa1..4103fb5dc 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -105,6 +105,10 @@ class HybridTimelineChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -113,7 +117,6 @@ class HybridTimelineChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', 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 e2192cfad..99d94ace9 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -90,6 +90,10 @@ class LocalTimelineChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -98,7 +102,6 @@ class LocalTimelineChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', note); } } diff --git a/packages/backend/src/server/api/stream/channels/main.ts b/packages/backend/src/server/api/stream/channels/main.ts index f93f62568..b7f840c6c 100644 --- a/packages/backend/src/server/api/stream/channels/main.ts +++ b/packages/backend/src/server/api/stream/channels/main.ts @@ -38,7 +38,11 @@ class MainChannel extends Channel { const note = await this.noteEntityService.pack(data.body.note.id, this.user, { detail: true, }); - this.connection.cacheNote(note); + + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + data.body.note = note; } break; @@ -51,7 +55,11 @@ class MainChannel extends Channel { const note = await this.noteEntityService.pack(data.body.id, this.user, { detail: true, }); - this.connection.cacheNote(note); + + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + data.body = note; } break; diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts index 67e5cd138..b735507e2 100644 --- a/packages/backend/src/server/api/stream/channels/role-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts @@ -73,6 +73,10 @@ class RoleTimelineChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -81,7 +85,6 @@ class RoleTimelineChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', note); } } else { 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 d9407ac5d..4b8df4368 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -130,6 +130,10 @@ class UserListChannel extends Channel { } } + if (this.user && (note.visibleUserIds?.includes(this.user.id) ?? note.mentions?.includes(this.user.id))) { + this.connection.cacheNote(note); + } + if (this.minimize && ['public', 'home'].includes(note.visibility)) { this.send('note', { id: note.id, myReaction: note.myReaction, @@ -138,7 +142,6 @@ class UserListChannel extends Channel { renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, }); } else { - this.connection.cacheNote(note); this.send('note', note); } } diff --git a/packages/frontend/src/scripts/use-note-capture.ts b/packages/frontend/src/scripts/use-note-capture.ts index 542d8ab52..db21dcba1 100644 --- a/packages/frontend/src/scripts/use-note-capture.ts +++ b/packages/frontend/src/scripts/use-note-capture.ts @@ -60,6 +60,8 @@ export function useNoteCapture(props: { } case 'pollVoted': { + if (note.value.poll == null) return; + const choice = body.choice; const choices = [...note.value.poll.choices]; @@ -84,8 +86,9 @@ export function useNoteCapture(props: { function capture(withHandler = false): void { if (connection) { - // TODO: このノートがストリーミング経由で流れてきた場合のみ sr する - connection.send(document.body.contains(props.rootEl.value ?? null as Node | null) ? 'sr' : 's', { id: note.value.id }); + if ($i && (note.value?.visibleUserIds?.includes($i.id) ?? note.value?.mentions?.includes($i.id))) { + connection.send(document.body.contains(props.rootEl.value ?? null as Node | null) ? 'sr' : 's', { id: note.value.id }); + } if (pureNote.value.id !== note.value.id) connection.send('s', { id: pureNote.value.id }); if (withHandler) connection.on('noteUpdated', onStreamNoteUpdated); }