Fix channels list pagination (#6679)

This commit is contained in:
takonomura 2020-08-30 18:18:34 +09:00 committed by GitHub
parent 42d1c67d56
commit d7df26d92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 7 deletions

View File

@ -44,7 +44,7 @@ export default Vue.extend({
tab: 'featured', tab: 'featured',
featuredPagination: { featuredPagination: {
endpoint: 'channels/featured', endpoint: 'channels/featured',
limit: 5, noPaging: true,
}, },
followingPagination: { followingPagination: {
endpoint: 'channels/followed', endpoint: 'channels/followed',

View File

@ -1,5 +1,8 @@
import $ from 'cafy';
import { ID } from '../../../../misc/cafy-id';
import define from '../../define'; import define from '../../define';
import { Channels, ChannelFollowings } from '../../../../models'; import { Channels, ChannelFollowings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
export const meta = { export const meta = {
tags: ['channels', 'account'], tags: ['channels', 'account'],
@ -8,6 +11,21 @@ export const meta = {
kind: 'read:channels', kind: 'read:channels',
params: {
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
limit: {
validator: $.optional.num.range(1, 100),
default: 5
},
},
res: { res: {
type: 'array' as const, type: 'array' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
@ -20,9 +38,12 @@ export const meta = {
}; };
export default define(meta, async (ps, me) => { export default define(meta, async (ps, me) => {
const followings = await ChannelFollowings.find({ const query = makePaginationQuery(ChannelFollowings.createQueryBuilder(), ps.sinceId, ps.untilId)
followerId: me.id, .andWhere({ followerId: me.id });
});
const followings = await query
.take(ps.limit!)
.getMany();
return await Promise.all(followings.map(x => Channels.pack(x.followeeId, me))); return await Promise.all(followings.map(x => Channels.pack(x.followeeId, me)));
}); });

View File

@ -1,5 +1,8 @@
import $ from 'cafy';
import { ID } from '../../../../misc/cafy-id';
import define from '../../define'; import define from '../../define';
import { Channels } from '../../../../models'; import { Channels } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
export const meta = { export const meta = {
tags: ['channels', 'account'], tags: ['channels', 'account'],
@ -8,6 +11,21 @@ export const meta = {
kind: 'read:channels', kind: 'read:channels',
params: {
sinceId: {
validator: $.optional.type(ID),
},
untilId: {
validator: $.optional.type(ID),
},
limit: {
validator: $.optional.num.range(1, 100),
default: 5
},
},
res: { res: {
type: 'array' as const, type: 'array' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
@ -20,9 +38,12 @@ export const meta = {
}; };
export default define(meta, async (ps, me) => { export default define(meta, async (ps, me) => {
const channels = await Channels.find({ const query = makePaginationQuery(Channels.createQueryBuilder(), ps.sinceId, ps.untilId)
userId: me.id, .andWhere({ userId: me.id });
});
const channels = await query
.take(ps.limit!)
.getMany();
return await Promise.all(channels.map(x => Channels.pack(x, me))); return await Promise.all(channels.map(x => Channels.pack(x, me)));
}); });