diff options
| author | takonomura <takonomura@users.noreply.github.com> | 2020-08-30 18:18:34 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-30 18:18:34 +0900 |
| commit | d7df26d92b3363df197afa47343d3a05e943e362 (patch) | |
| tree | f02588cbbc3f23c6d7336560c30b720af2659872 /src/server/api | |
| parent | fix(server): Fix #6669 (diff) | |
| download | sharkey-d7df26d92b3363df197afa47343d3a05e943e362.tar.gz sharkey-d7df26d92b3363df197afa47343d3a05e943e362.tar.bz2 sharkey-d7df26d92b3363df197afa47343d3a05e943e362.zip | |
Fix channels list pagination (#6679)
Diffstat (limited to 'src/server/api')
| -rw-r--r-- | src/server/api/endpoints/channels/followed.ts | 27 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/owned.ts | 27 |
2 files changed, 48 insertions, 6 deletions
diff --git a/src/server/api/endpoints/channels/followed.ts b/src/server/api/endpoints/channels/followed.ts index 05c2ec6a75..bd37d420f6 100644 --- a/src/server/api/endpoints/channels/followed.ts +++ b/src/server/api/endpoints/channels/followed.ts @@ -1,5 +1,8 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; import define from '../../define'; import { Channels, ChannelFollowings } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; export const meta = { tags: ['channels', 'account'], @@ -8,6 +11,21 @@ export const meta = { kind: 'read:channels', + params: { + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 5 + }, + }, + res: { type: 'array' as const, optional: false as const, nullable: false as const, @@ -20,9 +38,12 @@ export const meta = { }; export default define(meta, async (ps, me) => { - const followings = await ChannelFollowings.find({ - followerId: me.id, - }); + const query = makePaginationQuery(ChannelFollowings.createQueryBuilder(), ps.sinceId, ps.untilId) + .andWhere({ followerId: me.id }); + + const followings = await query + .take(ps.limit!) + .getMany(); return await Promise.all(followings.map(x => Channels.pack(x.followeeId, me))); }); diff --git a/src/server/api/endpoints/channels/owned.ts b/src/server/api/endpoints/channels/owned.ts index 9e563c0ac5..1a7e04640d 100644 --- a/src/server/api/endpoints/channels/owned.ts +++ b/src/server/api/endpoints/channels/owned.ts @@ -1,5 +1,8 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; import define from '../../define'; import { Channels } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; export const meta = { tags: ['channels', 'account'], @@ -8,6 +11,21 @@ export const meta = { kind: 'read:channels', + params: { + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 5 + }, + }, + res: { type: 'array' as const, optional: false as const, nullable: false as const, @@ -20,9 +38,12 @@ export const meta = { }; export default define(meta, async (ps, me) => { - const channels = await Channels.find({ - userId: me.id, - }); + const query = makePaginationQuery(Channels.createQueryBuilder(), ps.sinceId, ps.untilId) + .andWhere({ userId: me.id }); + + const channels = await query + .take(ps.limit!) + .getMany(); return await Promise.all(channels.map(x => Channels.pack(x, me))); }); |