Revert "refactor: 可読性のため一部でArray.prototype.atを使うように" (#115)

* Revert "refactor: 可読性のため一部で`Array.prototype.at`を使うように (#11274)"

This reverts commit 2b6dbd4fcb.

* Apply suggestions from code review

---------

Co-authored-by: okayurisotto <okayurisotto@proton.me>
This commit is contained in:
まっちゃとーにゅ
2023-07-25 19:58:08 +09:00
committed by GitHub
parent 3bde1b398a
commit 1e6389d990
19 changed files with 36 additions and 38 deletions

View File

@@ -627,7 +627,7 @@ export default abstract class Chart<T extends Schema> {
}
// 要求された範囲の最も古い箇所に位置するログが存在しなかったら
} 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({

View File

@@ -67,9 +67,8 @@ export function maximum(xs: number[]): number {
export function groupBy<T>(f: EndoRelation<T>, 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]);
}

View File

@@ -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)));

View File

@@ -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);

View File

@@ -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);

View File

@@ -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 });

View File

@@ -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;

View File

@@ -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 });

View File

@@ -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 });

View File

@@ -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;

View File

@@ -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,
);

View File

@@ -447,12 +447,12 @@ export async function testPaginationConsistency<Entity extends { id: string, cre
for (const limit of [1, 5, 10, 100, undefined]) {
// 1. sinceId/DateとuntilId/Dateで両端を指定して取得した結果が期待通りになっていること
if (ordering === 'desc') {
const end = expected.at(-1)!;
const end = expected[expected.length - 1];
let last = await fetchEntities(rangeToParam({ limit, since: end }));
const actual: Entity[] = [];
while (last.length !== 0) {
actual.push(...last);
last = await fetchEntities(rangeToParam({ limit, until: last.at(-1), since: end }));
last = await fetchEntities(rangeToParam({ limit, until: last[last.length - 1], since: end }));
}
actual.push(end);
assert.deepStrictEqual(
@@ -467,7 +467,7 @@ export async function testPaginationConsistency<Entity extends { id: string, cre
const actual: Entity[] = [];
while (last.length !== 0) {
actual.push(...last);
last = await fetchEntities(rangeToParam({ limit, since: last.at(-1) }));
last = await fetchEntities(rangeToParam({ limit, since: last[last.length - 1] }));
}
assert.deepStrictEqual(
actual.map(({ id, createdAt }) => id + ':' + createdAt),
@@ -480,7 +480,7 @@ export async function testPaginationConsistency<Entity extends { id: string, cre
const actual: Entity[] = [];
while (last.length !== 0) {
actual.push(...last);
last = await fetchEntities(rangeToParam({ limit, until: last.at(-1) }));
last = await fetchEntities(rangeToParam({ limit, until: last[last.length - 1] }));
}
assert.deepStrictEqual(
actual.map(({ id, createdAt }) => id + ':' + createdAt),