This commit is contained in:
parent
7f1794891c
commit
89956d6240
|
@ -80,62 +80,67 @@ def apply_filters(q, filters, author_id=None):
|
||||||
|
|
||||||
@query.field("get_shout")
|
@query.field("get_shout")
|
||||||
async def get_shout(_, info, slug: str):
|
async def get_shout(_, info, slug: str):
|
||||||
with local_session() as session:
|
try:
|
||||||
q = query_shouts()
|
with local_session() as session:
|
||||||
aliased_reaction = aliased(Reaction)
|
q = query_shouts()
|
||||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
aliased_reaction = aliased(Reaction)
|
||||||
q = q.filter(Shout.slug == slug)
|
q = add_reaction_stat_columns(q, aliased_reaction)
|
||||||
q = q.group_by(Shout.id)
|
q = q.filter(Shout.slug == slug)
|
||||||
|
q = q.group_by(Shout.id)
|
||||||
|
|
||||||
results = session.execute(q).first()
|
results = session.execute(q).first()
|
||||||
if results:
|
if results:
|
||||||
[
|
[
|
||||||
shout,
|
shout,
|
||||||
reacted_stat,
|
reacted_stat,
|
||||||
commented_stat,
|
commented_stat,
|
||||||
likes_stat,
|
likes_stat,
|
||||||
dislikes_stat,
|
dislikes_stat,
|
||||||
last_comment,
|
last_comment,
|
||||||
] = results
|
] = results
|
||||||
|
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||||
"reacted": reacted_stat,
|
"reacted": reacted_stat,
|
||||||
"commented": commented_stat,
|
"commented": commented_stat,
|
||||||
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
||||||
"last_comment": last_comment,
|
"last_comment": last_comment,
|
||||||
}
|
}
|
||||||
|
|
||||||
for author_caption in (
|
for author_caption in (
|
||||||
session.query(ShoutAuthor)
|
session.query(ShoutAuthor)
|
||||||
.join(Shout)
|
.join(Shout)
|
||||||
.where(
|
.where(
|
||||||
and_(
|
and_(
|
||||||
Shout.slug == slug,
|
Shout.slug == slug,
|
||||||
Shout.published_at.is_not(None),
|
Shout.published_at.is_not(None),
|
||||||
Shout.deleted_at.is_(None),
|
Shout.deleted_at.is_(None),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
):
|
||||||
|
for author in shout.authors:
|
||||||
|
if author.id == author_caption.author:
|
||||||
|
author.caption = author_caption.caption
|
||||||
|
main_topic = (
|
||||||
|
session.query(Topic.slug)
|
||||||
|
.join(
|
||||||
|
ShoutTopic,
|
||||||
|
and_(
|
||||||
|
ShoutTopic.topic == Topic.id,
|
||||||
|
ShoutTopic.shout == shout.id,
|
||||||
|
ShoutTopic.main.is_(True),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.first()
|
||||||
)
|
)
|
||||||
):
|
|
||||||
for author in shout.authors:
|
|
||||||
if author.id == author_caption.author:
|
|
||||||
author.caption = author_caption.caption
|
|
||||||
main_topic = (
|
|
||||||
session.query(Topic.slug)
|
|
||||||
.join(
|
|
||||||
ShoutTopic,
|
|
||||||
and_(
|
|
||||||
ShoutTopic.topic == Topic.id,
|
|
||||||
ShoutTopic.shout == shout.id,
|
|
||||||
ShoutTopic.main.is_(True),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
|
|
||||||
if main_topic:
|
if main_topic:
|
||||||
shout.main_topic = main_topic[0]
|
shout.main_topic = main_topic[0]
|
||||||
return shout
|
return shout
|
||||||
|
except Exception as _exc:
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shouts_by")
|
@query.field("load_shouts_by")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user