topicsRandom query
This commit is contained in:
parent
635be7e6a3
commit
ef6adbb4ea
|
@ -7,6 +7,7 @@ from base.orm import local_session
|
||||||
from base.resolvers import mutation, query
|
from base.resolvers import mutation, query
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
@query.field("topicsAll")
|
@query.field("topicsAll")
|
||||||
|
@ -81,3 +82,15 @@ def topic_unfollow(user, slug):
|
||||||
raise Exception("[resolvers.topics] follower not exist")
|
raise Exception("[resolvers.topics] follower not exist")
|
||||||
session.delete(sub)
|
session.delete(sub)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@query.field("topicsRandom")
|
||||||
|
async def topics_random(_, info):
|
||||||
|
topics = await TopicStorage.get_topics_all(1, 700)
|
||||||
|
normalized_topics = []
|
||||||
|
for topic in topics:
|
||||||
|
shouts_amount = await TopicStat.get_stat(topic.slug)
|
||||||
|
topic.stat = shouts_amount
|
||||||
|
if shouts_amount > 2:
|
||||||
|
normalized_topics.push(topic)
|
||||||
|
return random.choices(topics)[0:12]
|
||||||
|
|
|
@ -248,6 +248,7 @@ type Query {
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsAll(page: Int!, size: Int!): [Topic]!
|
topicsAll(page: Int!, size: Int!): [Topic]!
|
||||||
|
topicsRandom: [Topic]!
|
||||||
topicsByCommunity(community: String!): [Topic]!
|
topicsByCommunity(community: String!): [Topic]!
|
||||||
topicsByAuthor(author: String!): [Topic]!
|
topicsByAuthor(author: String!): [Topic]!
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user