shoutsByTopic, shoutsByAuthor and shoutsByCommunity pagination

This commit is contained in:
knst-kotov 2022-01-08 12:04:45 +03:00
parent 47364e37f4
commit bce71a6be8
2 changed files with 12 additions and 9 deletions

View File

@ -352,17 +352,18 @@ async def get_shout_comments(_, info, slug):
return comments
@query.field("shoutsByTopic")
async def shouts_by_topic(_, info, topic, limit):
async def shouts_by_topic(_, info, topic, page, size):
with local_session() as session:
shouts = session.query(Shout).\
join(ShoutTopic).\
where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\
order_by(desc(Shout.publishedAt)).\
limit(limit)
limit(size).\
offset(page * size)
return shouts
@query.field("shoutsByAuthor")
async def shouts_by_author(_, info, author, limit):
async def shouts_by_author(_, info, author, page, size):
with local_session() as session:
user = session.query(User).\
filter(User.slug == author).first()
@ -374,11 +375,12 @@ async def shouts_by_author(_, info, author, limit):
join(ShoutAuthor).\
where(and_(ShoutAuthor.user == user.id, Shout.publishedAt != None)).\
order_by(desc(Shout.publishedAt)).\
limit(limit)
limit(size).\
offset(page * size)
return shouts
@query.field("shoutsByCommunity")
async def shouts_by_community(_, info, community, limit):
async def shouts_by_community(_, info, community, page, size):
with local_session() as session:
#TODO fix postgres high load
@ -389,5 +391,6 @@ async def shouts_by_community(_, info, community, limit):
select(Topic.slug).where(Topic.community == community)\
))).\
order_by(desc(Shout.publishedAt)).\
limit(limit)
limit(size).\
offset(page * size)
return shouts

View File

@ -154,9 +154,9 @@ type Query {
# shouts
getShoutBySlug(slug: String!): Shout!
shoutsByTopic(topic: String!, limit: Int!): [Shout]!
shoutsByAuthor(author: String!, limit: Int!): [Shout]!
shoutsByCommunity(community: String!, limit: Int!): [Shout]!
shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]!
shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]!
shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]!
getShoutComments(slug: String!): [Comment]!
# mainpage