This commit is contained in:
parent
bf2c5b67e3
commit
8856bfc978
1
main.py
1
main.py
|
@ -16,7 +16,6 @@ from resolvers.webhook import WebhookEndpoint
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import resolvers
|
from services.schema import resolvers
|
||||||
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
||||||
import asyncio
|
|
||||||
from services.viewed import ViewedStorage
|
from services.viewed import ViewedStorage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,9 @@ class Shout(Base):
|
||||||
cover_caption = Column(String, nullable=True, comment="Cover image alt caption")
|
cover_caption = Column(String, nullable=True, comment="Cover image alt caption")
|
||||||
lead = Column(String, nullable=True)
|
lead = Column(String, nullable=True)
|
||||||
description = Column(String, nullable=True)
|
description = Column(String, nullable=True)
|
||||||
title = Column(String, nullable=True)
|
title = Column(String, nullable=False)
|
||||||
subtitle = Column(String, nullable=True)
|
subtitle = Column(String, nullable=True)
|
||||||
layout = Column(String, nullable=True)
|
layout = Column(String, nullable=False, default="article")
|
||||||
media = Column(JSON, nullable=True)
|
media = Column(JSON, nullable=True)
|
||||||
|
|
||||||
authors = relationship(lambda: Author, secondary="shout_author")
|
authors = relationship(lambda: Author, secondary="shout_author")
|
||||||
|
|
|
@ -14,6 +14,7 @@ from services.search import SearchService
|
||||||
from services.viewed import ViewedStorage
|
from services.viewed import ViewedStorage
|
||||||
from resolvers.topic import get_random_topic
|
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)
|
||||||
|
|
||||||
|
@ -324,15 +325,21 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0):
|
||||||
q = add_stat_columns(q)
|
q = add_stat_columns(q)
|
||||||
|
|
||||||
q = q.group_by(Shout.id).order_by(func.random()).limit(limit).offset(offset)
|
q = q.group_by(Shout.id).order_by(func.random()).limit(limit).offset(offset)
|
||||||
|
user_id = info.context.get("user_id")
|
||||||
return get_shouts_from_query(q, info.context.get("user_id"))
|
if user_id:
|
||||||
|
with local_session() as session:
|
||||||
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
|
if author:
|
||||||
|
return get_shouts_from_query(q, author.id)
|
||||||
|
else:
|
||||||
|
return get_shouts_from_query(q)
|
||||||
|
|
||||||
|
|
||||||
def get_shouts_from_query(q, user_id=None):
|
def get_shouts_from_query(q, author_id=None):
|
||||||
shouts = []
|
shouts = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
for [shout, reacted_stat, commented_stat, rating_stat, last_comment] in session.execute(
|
for [shout, reacted_stat, commented_stat, rating_stat, last_comment] in session.execute(
|
||||||
q, {"user_id": user_id}
|
q, {"author_id": author_id}
|
||||||
).unique():
|
).unique():
|
||||||
shouts.append(shout)
|
shouts.append(shout)
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
|
@ -407,8 +414,9 @@ async def load_shouts_random_top(_, _info, params):
|
||||||
|
|
||||||
return get_shouts_from_query(q)
|
return get_shouts_from_query(q)
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shouts_random_topic")
|
@query.field("load_shouts_random_topic")
|
||||||
async def load_shouts_random_topic(_, info, limit):
|
async def load_shouts_random_topic(_, info, limit: int = 10):
|
||||||
topic = get_random_topic()
|
topic = get_random_topic()
|
||||||
shouts = []
|
shouts = []
|
||||||
if topic:
|
if topic:
|
||||||
|
@ -419,9 +427,7 @@ async def load_shouts_random_topic(_, info, limit):
|
||||||
joinedload(Shout.topics),
|
joinedload(Shout.topics),
|
||||||
)
|
)
|
||||||
.join(ShoutTopic, and_(Shout.id == ShoutTopic.shout, ShoutTopic.topic == topic.id))
|
.join(ShoutTopic, and_(Shout.id == ShoutTopic.shout, ShoutTopic.topic == topic.id))
|
||||||
.where(
|
.filter(and_(Shout.deleted_at.is_(None), Shout.visibility == "public"))
|
||||||
and_(Shout.deleted_at.is_(None), Shout.layout.is_not(None), Shout.visibility == "public")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
q = add_stat_columns(q)
|
q = add_stat_columns(q)
|
||||||
|
|
|
@ -121,13 +121,13 @@ type Shout {
|
||||||
deleted_by: Author
|
deleted_by: Author
|
||||||
authors: [Author]
|
authors: [Author]
|
||||||
communities: [Community]
|
communities: [Community]
|
||||||
title: String
|
title: String!
|
||||||
subtitle: String
|
subtitle: String
|
||||||
lang: String
|
lang: String
|
||||||
community: String
|
community: String
|
||||||
cover: String
|
cover: String
|
||||||
cover_caption: String
|
cover_caption: String
|
||||||
layout: String
|
layout: String!
|
||||||
version_of: String
|
version_of: String
|
||||||
visibility: ShoutVisibility
|
visibility: ShoutVisibility
|
||||||
updated_at: Int
|
updated_at: Int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user