shoutsByTopic, shoutsByAuthor and shoutsByCommunity pagination
This commit is contained in:
parent
47364e37f4
commit
bce71a6be8
|
@ -352,17 +352,18 @@ async def get_shout_comments(_, info, slug):
|
||||||
return comments
|
return comments
|
||||||
|
|
||||||
@query.field("shoutsByTopic")
|
@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:
|
with local_session() as session:
|
||||||
shouts = session.query(Shout).\
|
shouts = session.query(Shout).\
|
||||||
join(ShoutTopic).\
|
join(ShoutTopic).\
|
||||||
where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\
|
where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\
|
||||||
order_by(desc(Shout.publishedAt)).\
|
order_by(desc(Shout.publishedAt)).\
|
||||||
limit(limit)
|
limit(size).\
|
||||||
|
offset(page * size)
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
@query.field("shoutsByAuthor")
|
@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:
|
with local_session() as session:
|
||||||
user = session.query(User).\
|
user = session.query(User).\
|
||||||
filter(User.slug == author).first()
|
filter(User.slug == author).first()
|
||||||
|
@ -374,11 +375,12 @@ async def shouts_by_author(_, info, author, limit):
|
||||||
join(ShoutAuthor).\
|
join(ShoutAuthor).\
|
||||||
where(and_(ShoutAuthor.user == user.id, Shout.publishedAt != None)).\
|
where(and_(ShoutAuthor.user == user.id, Shout.publishedAt != None)).\
|
||||||
order_by(desc(Shout.publishedAt)).\
|
order_by(desc(Shout.publishedAt)).\
|
||||||
limit(limit)
|
limit(size).\
|
||||||
|
offset(page * size)
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
@query.field("shoutsByCommunity")
|
@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:
|
with local_session() as session:
|
||||||
|
|
||||||
#TODO fix postgres high load
|
#TODO fix postgres high load
|
||||||
|
@ -389,5 +391,6 @@ async def shouts_by_community(_, info, community, limit):
|
||||||
select(Topic.slug).where(Topic.community == community)\
|
select(Topic.slug).where(Topic.community == community)\
|
||||||
))).\
|
))).\
|
||||||
order_by(desc(Shout.publishedAt)).\
|
order_by(desc(Shout.publishedAt)).\
|
||||||
limit(limit)
|
limit(size).\
|
||||||
|
offset(page * size)
|
||||||
return shouts
|
return shouts
|
||||||
|
|
|
@ -154,9 +154,9 @@ type Query {
|
||||||
|
|
||||||
# shouts
|
# shouts
|
||||||
getShoutBySlug(slug: String!): Shout!
|
getShoutBySlug(slug: String!): Shout!
|
||||||
shoutsByTopic(topic: String!, limit: Int!): [Shout]!
|
shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]!
|
||||||
shoutsByAuthor(author: String!, limit: Int!): [Shout]!
|
shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]!
|
||||||
shoutsByCommunity(community: String!, limit: Int!): [Shout]!
|
shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]!
|
||||||
getShoutComments(slug: String!): [Comment]!
|
getShoutComments(slug: String!): [Comment]!
|
||||||
|
|
||||||
# mainpage
|
# mainpage
|
||||||
|
|
Loading…
Reference in New Issue
Block a user