From 1e6389d990fd447680e31619382ea0191f0f0d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:58:08 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"refactor:=20=E5=8F=AF=E8=AA=AD?= =?UTF-8?q?=E6=80=A7=E3=81=AE=E3=81=9F=E3=82=81=E4=B8=80=E9=83=A8=E3=81=A7?= =?UTF-8?q?`Array.prototype.at`=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB"=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "refactor: 可読性のため一部で`Array.prototype.at`を使うように (#11274)" This reverts commit 2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b. * Apply suggestions from code review --------- Co-authored-by: okayurisotto --- packages/backend/src/core/chart/core.ts | 2 +- packages/backend/src/misc/prelude/array.ts | 5 ++--- .../queue/processors/CleanRemoteFilesProcessorService.ts | 2 +- .../src/queue/processors/DeleteAccountProcessorService.ts | 4 ++-- .../queue/processors/DeleteDriveFilesProcessorService.ts | 2 +- .../queue/processors/ExportBlockingProcessorService.ts | 2 +- .../queue/processors/ExportFavoritesProcessorService.ts | 2 +- .../queue/processors/ExportFollowingProcessorService.ts | 2 +- .../src/queue/processors/ExportMutingProcessorService.ts | 2 +- .../src/queue/processors/ExportNotesProcessorService.ts | 2 +- packages/backend/src/server/ActivityPubServerService.ts | 6 +++--- packages/backend/test/utils.ts | 8 ++++---- packages/frontend/src/components/MkDrive.vue | 4 ++-- packages/frontend/src/components/MkMiniChart.vue | 4 ++-- packages/frontend/src/components/MkPageWindow.vue | 2 +- packages/frontend/src/components/MkPagination.vue | 4 ++-- packages/frontend/src/scripts/array.ts | 5 ++--- packages/frontend/src/widgets/server-metric/cpu-mem.vue | 8 ++++---- packages/frontend/src/widgets/server-metric/net.vue | 8 ++++---- 19 files changed, 36 insertions(+), 38 deletions(-) diff --git a/packages/backend/src/core/chart/core.ts b/packages/backend/src/core/chart/core.ts index 7a89233eda..5717024351 100644 --- a/packages/backend/src/core/chart/core.ts +++ b/packages/backend/src/core/chart/core.ts @@ -627,7 +627,7 @@ export default abstract class Chart { } // 要求された範囲の最も古い箇所に位置するログが存在しなかったら - } else if (!isTimeSame(new Date(logs.at(-1)!.date * 1000), gt)) { + } else if (!isTimeSame(new Date(logs[logs.length - 1].date * 1000), gt)) { // 要求された範囲の最も古い箇所時点での最も新しいログを持ってきて末尾に追加する // (隙間埋めできないため) const outdatedLog = await repository.findOne({ diff --git a/packages/backend/src/misc/prelude/array.ts b/packages/backend/src/misc/prelude/array.ts index 2524eacfb3..0b2830cb7b 100644 --- a/packages/backend/src/misc/prelude/array.ts +++ b/packages/backend/src/misc/prelude/array.ts @@ -67,9 +67,8 @@ export function maximum(xs: number[]): number { export function groupBy(f: EndoRelation, xs: T[]): T[][] { const groups = [] as T[][]; for (const x of xs) { - const lastGroup = groups.at(-1); - if (lastGroup !== undefined && f(lastGroup[0], x)) { - lastGroup.push(x); + if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) { + groups[groups.length - 1].push(x); } else { groups.push([x]); } diff --git a/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts b/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts index 6f887089eb..4a22d86a6f 100644 --- a/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts +++ b/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts @@ -51,7 +51,7 @@ export class CleanRemoteFilesProcessorService { break; } - cursor = files.at(-1)?.id ?? null; + cursor = files[files.length - 1].id; await Promise.all(files.map(file => this.driveService.deleteFileSync(file, true))); diff --git a/packages/backend/src/queue/processors/DeleteAccountProcessorService.ts b/packages/backend/src/queue/processors/DeleteAccountProcessorService.ts index 3b7db5f05c..f9679eae39 100644 --- a/packages/backend/src/queue/processors/DeleteAccountProcessorService.ts +++ b/packages/backend/src/queue/processors/DeleteAccountProcessorService.ts @@ -70,7 +70,7 @@ export class DeleteAccountProcessorService { break; } - cursor = notes.at(-1)?.id ?? null; + cursor = notes[notes.length - 1].id; await this.notesRepository.delete(notes.map(note => note.id)); @@ -101,7 +101,7 @@ export class DeleteAccountProcessorService { break; } - cursor = files.at(-1)?.id ?? null; + cursor = files[files.length - 1].id; for (const file of files) { await this.driveService.deleteFileSync(file); diff --git a/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts b/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts index 07e3762330..11ae994b85 100644 --- a/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts +++ b/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts @@ -59,7 +59,7 @@ export class DeleteDriveFilesProcessorService { break; } - cursor = files.at(-1)?.id ?? null; + cursor = files[files.length - 1].id; for (const file of files) { await this.driveService.deleteFileSync(file); diff --git a/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts b/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts index d100c6d09f..cb58377b38 100644 --- a/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts @@ -72,7 +72,7 @@ export class ExportBlockingProcessorService { break; } - cursor = blockings.at(-1)?.id ?? null; + cursor = blockings[blockings.length - 1].id; for (const block of blockings) { const u = await this.usersRepository.findOneBy({ id: block.blockeeId }); diff --git a/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts b/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts index 2be42b1a7a..76c38a6b86 100644 --- a/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts @@ -94,7 +94,7 @@ export class ExportFavoritesProcessorService { break; } - cursor = favorites.at(-1)?.id ?? null; + cursor = favorites[favorites.length - 1].id; for (const favorite of favorites) { let poll: Poll | undefined; diff --git a/packages/backend/src/queue/processors/ExportFollowingProcessorService.ts b/packages/backend/src/queue/processors/ExportFollowingProcessorService.ts index d54e5e0b34..8726cb1402 100644 --- a/packages/backend/src/queue/processors/ExportFollowingProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportFollowingProcessorService.ts @@ -79,7 +79,7 @@ export class ExportFollowingProcessorService { break; } - cursor = followings.at(-1)?.id ?? null; + cursor = followings[followings.length - 1].id; for (const following of followings) { const u = await this.usersRepository.findOneBy({ id: following.followeeId }); diff --git a/packages/backend/src/queue/processors/ExportMutingProcessorService.ts b/packages/backend/src/queue/processors/ExportMutingProcessorService.ts index 030e38931e..3c93323b57 100644 --- a/packages/backend/src/queue/processors/ExportMutingProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportMutingProcessorService.ts @@ -76,7 +76,7 @@ export class ExportMutingProcessorService { break; } - cursor = mutes.at(-1)?.id ?? null; + cursor = mutes[mutes.length - 1].id; for (const mute of mutes) { const u = await this.usersRepository.findOneBy({ id: mute.muteeId }); diff --git a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts index 94c81a3cf8..13f88e37ce 100644 --- a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts @@ -94,7 +94,7 @@ export class ExportNotesProcessorService { break; } - cursor = notes.at(-1)?.id ?? null; + cursor = notes[notes.length - 1].id; for (const note of notes) { let poll: Poll | undefined; diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts index 634f5f0a4e..f751709345 100644 --- a/packages/backend/src/server/ActivityPubServerService.ts +++ b/packages/backend/src/server/ActivityPubServerService.ts @@ -181,7 +181,7 @@ export class ActivityPubServerService { undefined, inStock ? `${partOf}?${url.query({ page: 'true', - cursor: followings.at(-1)!.id, + cursor: followings[followings.length - 1].id, })}` : undefined, ); @@ -273,7 +273,7 @@ export class ActivityPubServerService { undefined, inStock ? `${partOf}?${url.query({ page: 'true', - cursor: followings.at(-1)!.id, + cursor: followings[followings.length - 1].id, })}` : undefined, ); @@ -398,7 +398,7 @@ export class ActivityPubServerService { })}` : undefined, notes.length ? `${partOf}?${url.query({ page: 'true', - until_id: notes.at(-1)!.id, + until_id: notes[notes.length - 1].id, })}` : undefined, ); diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts index 31ea3e5ab8..48947072e3 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.ts @@ -447,12 +447,12 @@ export async function testPaginationConsistency id + ':' + createdAt), @@ -480,7 +480,7 @@ export async function testPaginationConsistency id + ':' + createdAt), diff --git a/packages/frontend/src/components/MkDrive.vue b/packages/frontend/src/components/MkDrive.vue index aff227da40..201a6ccdc8 100644 --- a/packages/frontend/src/components/MkDrive.vue +++ b/packages/frontend/src/components/MkDrive.vue @@ -568,7 +568,7 @@ function fetchMoreFolders() { os.api('drive/folders', { folderId: folder.value ? folder.value.id : null, type: props.type, - untilId: folders.value.at(-1)?.id, + untilId: folders.value[folders.value.length - 1].id, limit: max + 1, }).then(folders => { if (folders.length === max + 1) { @@ -591,7 +591,7 @@ function fetchMoreFiles() { os.api('drive/files', { folderId: folder.value ? folder.value.id : null, type: props.type, - untilId: files.value.at(-1)?.id, + untilId: files.value[files.value.length - 1].id, limit: max + 1, }).then(files => { if (files.length === max + 1) { diff --git a/packages/frontend/src/components/MkMiniChart.vue b/packages/frontend/src/components/MkMiniChart.vue index e884455709..89050e10f0 100644 --- a/packages/frontend/src/components/MkMiniChart.vue +++ b/packages/frontend/src/components/MkMiniChart.vue @@ -59,8 +59,8 @@ function draw(): void { polygonPoints = `0,${ viewBoxY } ${ polylinePoints } ${ viewBoxX },${ viewBoxY }`; - headX = _polylinePoints.at(-1)![0]; - headY = _polylinePoints.at(-1)![1]; + headX = _polylinePoints[_polylinePoints.length - 1][0]; + headY = _polylinePoints[_polylinePoints.length - 1][1]; } watch(() => props.src, draw, { immediate: true }); diff --git a/packages/frontend/src/components/MkPageWindow.vue b/packages/frontend/src/components/MkPageWindow.vue index 6e35ad4241..6318a9fd70 100644 --- a/packages/frontend/src/components/MkPageWindow.vue +++ b/packages/frontend/src/components/MkPageWindow.vue @@ -120,7 +120,7 @@ const contextmenu = $computed(() => ([{ function back() { history.pop(); - router.replace(history.at(-1)!.path, history.at(-1)!.key); + router.replace(history[history.length - 1].path, history[history.length - 1].key); } function reload() { diff --git a/packages/frontend/src/components/MkPagination.vue b/packages/frontend/src/components/MkPagination.vue index 693098f2bd..989313b182 100644 --- a/packages/frontend/src/components/MkPagination.vue +++ b/packages/frontend/src/components/MkPagination.vue @@ -233,7 +233,7 @@ const fetchMore = async (): Promise => { ...(props.pagination.offsetMode ? { offset: offset.value, } : { - untilId: Array.from(items.value.keys()).at(-1), + untilId: Array.from(items.value.keys())[items.value.size - 1], }), }).then(res => { for (let i = 0; i < res.length; i++) { @@ -297,7 +297,7 @@ const fetchMoreAhead = async (): Promise => { ...(props.pagination.offsetMode ? { offset: offset.value, } : { - sinceId: Array.from(items.value.keys()).at(-1), + sinceId: Array.from(items.value.keys())[items.value.size - 1], }), }).then(res => { if (res.length === 0) { diff --git a/packages/frontend/src/scripts/array.ts b/packages/frontend/src/scripts/array.ts index c9a146e707..4620c8b735 100644 --- a/packages/frontend/src/scripts/array.ts +++ b/packages/frontend/src/scripts/array.ts @@ -78,9 +78,8 @@ export function maximum(xs: number[]): number { export function groupBy(f: EndoRelation, xs: T[]): T[][] { const groups = [] as T[][]; for (const x of xs) { - const lastGroup = groups.at(-1); - if (lastGroup !== undefined && f(lastGroup[0], x)) { - lastGroup.push(x); + if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) { + groups[groups.length - 1].push(x); } else { groups.push([x]); } diff --git a/packages/frontend/src/widgets/server-metric/cpu-mem.vue b/packages/frontend/src/widgets/server-metric/cpu-mem.vue index b9ba400b4d..c178ba5171 100644 --- a/packages/frontend/src/widgets/server-metric/cpu-mem.vue +++ b/packages/frontend/src/widgets/server-metric/cpu-mem.vue @@ -121,10 +121,10 @@ function onStats(connStats) { cpuPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${cpuPolylinePoints} ${viewBoxX},${viewBoxY}`; memPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${memPolylinePoints} ${viewBoxX},${viewBoxY}`; - cpuHeadX = cpuPolylinePointsStats.at(-1)![0]; - cpuHeadY = cpuPolylinePointsStats.at(-1)![1]; - memHeadX = memPolylinePointsStats.at(-1)![0]; - memHeadY = memPolylinePointsStats.at(-1)![1]; + cpuHeadX = cpuPolylinePointsStats[cpuPolylinePointsStats.length - 1][0]; + cpuHeadY = cpuPolylinePointsStats[cpuPolylinePointsStats.length - 1][1]; + memHeadX = memPolylinePointsStats[memPolylinePointsStats.length - 1][0]; + memHeadY = memPolylinePointsStats[memPolylinePointsStats.length - 1][1]; cpuP = (connStats.cpu * 100).toFixed(0); memP = (connStats.mem.active / props.meta.mem.total * 100).toFixed(0); diff --git a/packages/frontend/src/widgets/server-metric/net.vue b/packages/frontend/src/widgets/server-metric/net.vue index 817a422e63..5a9134078d 100644 --- a/packages/frontend/src/widgets/server-metric/net.vue +++ b/packages/frontend/src/widgets/server-metric/net.vue @@ -94,10 +94,10 @@ function onStats(connStats) { inPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${inPolylinePoints} ${viewBoxX},${viewBoxY}`; outPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${outPolylinePoints} ${viewBoxX},${viewBoxY}`; - inHeadX = inPolylinePointsStats.at(-1)![0]; - inHeadY = inPolylinePointsStats.at(-1)![1]; - outHeadX = outPolylinePointsStats.at(-1)![0]; - outHeadY = outPolylinePointsStats.at(-1)![1]; + inHeadX = inPolylinePointsStats[inPolylinePointsStats.length - 1][0]; + inHeadY = inPolylinePointsStats[inPolylinePointsStats.length - 1][1]; + outHeadX = outPolylinePointsStats[outPolylinePointsStats.length - 1][0]; + outHeadY = outPolylinePointsStats[outPolylinePointsStats.length - 1][1]; inRecent = connStats.net.rx; outRecent = connStats.net.tx;