From 98469117bf4bbf04f25b9d4db02561f32a493a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=91=E3=81=A3=E3=81=A1?= <50144466+sim1222@users.noreply.github.com> Date: Sat, 14 Jan 2023 06:18:58 +0900 Subject: [PATCH] fix: follow request list api pagination (#9548) * fix: follow request list api pagination * fix: improve alias Co-authored-by: syuilo Co-authored-by: syuilo --- .../api/endpoints/following/requests/list.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/following/requests/list.ts b/packages/backend/src/server/api/endpoints/following/requests/list.ts index 5b11633e6..f581023e2 100644 --- a/packages/backend/src/server/api/endpoints/following/requests/list.ts +++ b/packages/backend/src/server/api/endpoints/following/requests/list.ts @@ -1,5 +1,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; +import { QueryService } from '@/core/QueryService.js'; import type { FollowRequestsRepository } from '@/models/index.js'; import { FollowRequestEntityService } from '@/core/entities/FollowRequestEntityService.js'; import { DI } from '@/di-symbols.js'; @@ -40,7 +41,11 @@ export const meta = { export const paramDef = { type: 'object', - properties: {}, + properties: { + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, + }, required: [], } as const; @@ -52,13 +57,16 @@ export default class extends Endpoint { private followRequestsRepository: FollowRequestsRepository, private followRequestEntityService: FollowRequestEntityService, + private queryService: QueryService, ) { super(meta, paramDef, async (ps, me) => { - const reqs = await this.followRequestsRepository.findBy({ - followeeId: me.id, - }); + const query = this.queryService.makePaginationQuery(this.followRequestsRepository.createQueryBuilder('request'), ps.sinceId, ps.untilId); - return await Promise.all(reqs.map(req => this.followRequestEntityService.pack(req))); + const requests = await query + .take(ps.limit) + .getMany(); + + return await Promise.all(requests.map(req => this.followRequestEntityService.pack(req))); }); } }