Skip to content
Snippets Groups Projects
Unverified Commit d7df26d9 authored by takonomura's avatar takonomura Committed by GitHub
Browse files

Fix channels list pagination (#6679)

parent 42d1c67d
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ export default Vue.extend({
tab: 'featured',
featuredPagination: {
endpoint: 'channels/featured',
limit: 5,
noPaging: true,
},
followingPagination: {
endpoint: 'channels/followed',
......
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)));
});
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)));
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment