From d36be50b1c8f6a6d7ccef4fdfe3f0f6e39d0433c 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: Tue, 1 Apr 2025 02:56:21 +0900 Subject: [PATCH] =?UTF-8?q?enhance(timeline):=20=E3=82=BF=E3=83=96?= =?UTF-8?q?=E3=81=8C=E3=83=90=E3=83=83=E3=82=AF=E3=82=B0=E3=83=A9=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=81=8B=E3=82=89=E6=88=BB=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=8D=E3=81=9F=E6=99=82=E3=80=81=E3=83=8E=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=AE=E5=8F=96=E5=BE=97=E3=82=92=E3=81=BE=E3=81=A8=E3=82=81?= =?UTF-8?q?=E3=81=A6=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=20(Missk?= =?UTF-8?q?eyIO#960)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/components/MkTimeline.vue | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/packages/frontend/src/components/MkTimeline.vue b/packages/frontend/src/components/MkTimeline.vue index f64046d52..228d22244 100644 --- a/packages/frontend/src/components/MkTimeline.vue +++ b/packages/frontend/src/components/MkTimeline.vue @@ -71,26 +71,33 @@ const tlComponent = shallowRef>(); let tlNotesCount = 0; const notVisibleNoteData = new Array(); +async function fulfillNoteData(data) { + // チェックするプロパティはなんでも良い + // minimizeが有効でid以外が存在しない場合は取得する + if (!data.visibility) { + const res = await window.fetch(`/notes/${data.id}.json`, { + method: 'GET', + credentials: 'omit', + headers: { + 'Authorization': 'anonymous', + 'X-Client-Transaction-Id': generateClientTransactionId('misskey'), + }, + }); + if (!res.ok) return null; + return deepMerge(data, await res.json()); + } + + return data; +} + async function prepend(data) { if (tlComponent.value == null) return; let note = data; if (!document.hidden) { - // チェックするプロパティはなんでも良い - // minimizeが有効でid以外が存在しない場合は取得する - if (!data.visibility) { - const res = await window.fetch(`/notes/${data.id}.json`, { - method: 'GET', - credentials: 'omit', - headers: { - 'Authorization': 'anonymous', - 'X-Client-Transaction-Id': generateClientTransactionId('misskey'), - }, - }); - if (!res.ok) return; - note = deepMerge(data, await res.json()); - } + note = await fulfillNoteData(data); + if (note == null) return; tlNotesCount++; @@ -119,16 +126,20 @@ async function loadUnloadedNotes() { if (tlComponent.value == null) return; if (notVisibleNoteData.length === 0) return; - if (notVisibleNoteData.length >= 10) { - tlComponent.value.pagingComponent?.deleteItem(); - tlComponent.value.pagingComponent?.stopFetch(); - } + tlComponent.value.pagingComponent?.stopFetch(); + try { + const items = [...notVisibleNoteData]; + notVisibleNoteData.length = 0; - while (notVisibleNoteData.length > 0) { - await prepend(notVisibleNoteData.shift()); - } + const notes = await Promise.allSettled(items.map(fulfillNoteData)); + if (items.length >= 10) tlComponent.value.pagingComponent?.deleteItem(); - tlComponent.value.pagingComponent?.startFetch(); + for (const note of notes.filter(i => i.status === 'fulfilled' && i.value != null)) { + await prepend((note as PromiseFulfilledResult).value); + } + } finally { + tlComponent.value.pagingComponent?.startFetch(); + } } let connection: Misskey.ChannelConnection | null = null;