This commit is contained in:
parent
4e769332b7
commit
d3ea567797
|
@ -26,6 +26,7 @@ from resolvers.reader import (
|
||||||
load_shouts_random_top,
|
load_shouts_random_top,
|
||||||
load_shouts_search,
|
load_shouts_search,
|
||||||
load_shouts_unrated,
|
load_shouts_unrated,
|
||||||
|
load_shouts_random_topic
|
||||||
)
|
)
|
||||||
from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community
|
from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ __all__ = [
|
||||||
"load_shouts_followed",
|
"load_shouts_followed",
|
||||||
"load_shouts_unrated",
|
"load_shouts_unrated",
|
||||||
"load_shouts_random_top",
|
"load_shouts_random_top",
|
||||||
|
"load_shouts_random_topic",
|
||||||
# follower
|
# follower
|
||||||
"follow",
|
"follow",
|
||||||
"unfollow",
|
"unfollow",
|
||||||
|
|
|
@ -12,7 +12,7 @@ from services.db import local_session
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
from services.search import SearchService
|
from services.search import SearchService
|
||||||
from services.viewed import ViewedStorage
|
from services.viewed import ViewedStorage
|
||||||
|
from resolvers.topic import get_random_topic
|
||||||
|
|
||||||
def add_stat_columns(q):
|
def add_stat_columns(q):
|
||||||
aliased_reaction = aliased(Reaction)
|
aliased_reaction = aliased(Reaction)
|
||||||
|
@ -407,3 +407,28 @@ async def load_shouts_random_top(_, _info, params):
|
||||||
# print(q.compile(compile_kwargs={"literal_binds": True}))
|
# print(q.compile(compile_kwargs={"literal_binds": True}))
|
||||||
|
|
||||||
return get_shouts_from_query(q)
|
return get_shouts_from_query(q)
|
||||||
|
|
||||||
|
@query.field("load_shouts_random_topic")
|
||||||
|
async def load_shouts_random_topic(_, info, limit):
|
||||||
|
topic = get_random_topic()
|
||||||
|
shouts = []
|
||||||
|
if topic:
|
||||||
|
q = (
|
||||||
|
select(Shout)
|
||||||
|
.options(
|
||||||
|
joinedload(Shout.authors),
|
||||||
|
joinedload(Shout.topics),
|
||||||
|
)
|
||||||
|
.join(ShoutTopic, and_(Shout.id == ShoutTopic.shout, ShoutTopic.topic == topic.id))
|
||||||
|
.where(
|
||||||
|
and_(Shout.deletedAt.is_(None), Shout.layout.is_not(None), Shout.visibility == "public")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
q = add_stat_columns(q)
|
||||||
|
|
||||||
|
q = q.group_by(Shout.id).order_by(desc(Shout.createdAt)).limit(limit)
|
||||||
|
|
||||||
|
shouts = get_shouts_from_query(q)
|
||||||
|
|
||||||
|
return {"topic": topic, "shouts": shouts}
|
||||||
|
|
|
@ -187,3 +187,15 @@ async def get_topics_random(_, info, amount=12):
|
||||||
topics.append(topic)
|
topics.append(topic)
|
||||||
|
|
||||||
return topics
|
return topics
|
||||||
|
|
||||||
|
|
||||||
|
def get_random_topic():
|
||||||
|
q = select(Topic)
|
||||||
|
q = q.join(ShoutTopic)
|
||||||
|
q = q.group_by(Topic.id)
|
||||||
|
q = q.having(func.count(distinct(ShoutTopic.shout)) > 10)
|
||||||
|
q = q.order_by(func.random()).limit(1)
|
||||||
|
topic = None
|
||||||
|
with local_session() as session:
|
||||||
|
topic = session.execute(q).first()
|
||||||
|
return topic
|
||||||
|
|
|
@ -364,6 +364,7 @@ type Query {
|
||||||
load_shouts_feed(options: LoadShoutsOptions): [Shout]
|
load_shouts_feed(options: LoadShoutsOptions): [Shout]
|
||||||
load_shouts_unrated(limit: Int, offset: Int): [Shout]
|
load_shouts_unrated(limit: Int, offset: Int): [Shout]
|
||||||
load_shouts_random_top(options: LoadShoutsOptions): [Shout]
|
load_shouts_random_top(options: LoadShoutsOptions): [Shout]
|
||||||
|
load_shouts_random_topic(limit: Int!): Result! # { topic shouts }
|
||||||
load_shouts_drafts: [Shout]
|
load_shouts_drafts: [Shout]
|
||||||
|
|
||||||
# topic
|
# topic
|
||||||
|
|
Loading…
Reference in New Issue
Block a user