paginated topics and authors

This commit is contained in:
tonyrewin 2022-08-30 09:42:51 +03:00
parent c15f2578b7
commit e4542ec5ca
4 changed files with 11 additions and 6 deletions

View File

@ -160,5 +160,8 @@ def author_unfollow(user, slug):
session.commit() session.commit()
@query.field("authorsAll") @query.field("authorsAll")
def get_authors_all(_, info): def get_authors_all(_, info, page, size):
return UserStorage.get_all_users() end = page * size
start = end - size
return UserStorage.get_all_users()[start:end]

View File

@ -9,7 +9,7 @@ from auth.authenticate import login_required
from sqlalchemy import and_ from sqlalchemy import and_
@query.field("topicsAll") @query.field("topicsAll")
async def topics_by_slugs(_, info, page = 1, size = 50): async def topics_all(_, info, page = 1, size = 50):
topics = await TopicStorage.get_topics_all(page, size) topics = await TopicStorage.get_topics_all(page, size)
for topic in topics: for topic in topics:
topic.stat = await TopicStat.get_stat(topic.slug) topic.stat = await TopicStat.get_stat(topic.slug)

View File

@ -221,7 +221,7 @@ type Query {
userFollowedCommunities(slug: String!): [Community]! userFollowedCommunities(slug: String!): [Community]!
userReactedShouts(slug: String!): [Shout]! # test userReactedShouts(slug: String!): [Shout]! # test
getUserRoles(slug: String!): [Role]! getUserRoles(slug: String!): [Role]!
authorsAll: [User]! authorsAll(page: Int!, size: Int!): [User]!
# shouts # shouts
getShoutBySlug(slug: String!): Shout! getShoutBySlug(slug: String!): Shout!

View File

@ -27,10 +27,12 @@ class TopicStorage:
return topic return topic
@staticmethod @staticmethod
async def get_topics_all(): async def get_topics_all(page, size):
end = page * size
start = end - size
self = TopicStorage self = TopicStorage
async with self.lock: async with self.lock:
return self.topics.values() return self.topics.values()[start:end]
@staticmethod @staticmethod
async def get_topics_by_slugs(slugs): async def get_topics_by_slugs(slugs):