From 8249819a6e2cc9b863218d58b6503fa85bb9ab66 Mon Sep 17 00:00:00 2001 From: RyotaK <49341894+Ry0taK@users.noreply.github.com> Date: Sat, 11 Mar 2023 19:38:15 +0900 Subject: [PATCH] =?UTF-8?q?createdAt=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8Fid?= =?UTF-8?q?=E3=81=A7=E7=B5=9E=E3=82=8A=E8=BE=BC=E3=82=80=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/misc/id/aid.ts | 4 ++-- packages/backend/src/server/api/endpoints/notes/timeline.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/misc/id/aid.ts b/packages/backend/src/misc/id/aid.ts index 19c8546f95..158e5699c1 100644 --- a/packages/backend/src/misc/id/aid.ts +++ b/packages/backend/src/misc/id/aid.ts @@ -6,7 +6,7 @@ import * as crypto from 'node:crypto'; const TIME2000 = 946684800000; let counter = crypto.randomBytes(2).readUInt16LE(0); -function getTime(time: number): string { +export function getTimeId(time: number): string { time = time - TIME2000; if (time < 0) time = 0; @@ -21,5 +21,5 @@ export function genAid(date: Date): string { const t = date.getTime(); if (isNaN(t)) throw 'Failed to create AID: Invalid Date'; counter++; - return getTime(t) + getNoise(); + return getTimeId(t) + getNoise(); } diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index e6de087c4a..c7f42c91a6 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -6,6 +6,7 @@ import { QueryService } from '@/core/QueryService.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; +import { getTimeId } from '@/misc/id/aid.js'; export const meta = { tags: ['notes'], @@ -63,10 +64,11 @@ export default class extends Endpoint { .where('following.followerId = :followerId', { followerId: me.id }) .getMany(); + const minId = getTimeId(new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)).getTime()) + '00'; // 30日前まで //#region Construct query const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) - .andWhere('note.createdAt > :minDate', { minDate: new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)) }) // 30日前まで + .andWhere('note.id > :minId', { minId }) .innerJoinAndSelect('note.user', 'user') .leftJoinAndSelect('user.avatar', 'avatar') .leftJoinAndSelect('user.banner', 'banner')