This commit is contained in:
@@ -100,18 +100,15 @@ async def get_shout(_, info, slug: str):
|
||||
if results:
|
||||
[
|
||||
shout,
|
||||
reacted_stat,
|
||||
commented_stat,
|
||||
likes_stat,
|
||||
dislikes_stat,
|
||||
rating_stat,
|
||||
last_reaction_at,
|
||||
] = results
|
||||
|
||||
shout.stat = {
|
||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||
"reacted": reacted_stat,
|
||||
# "viewed": await ViewedStorage.get_shout(shout.slug),
|
||||
"commented": commented_stat,
|
||||
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reaction_at,
|
||||
}
|
||||
|
||||
@@ -165,7 +162,7 @@ async def load_shouts_by(_, _info, options):
|
||||
}
|
||||
offset: 0
|
||||
limit: 50
|
||||
order_by: "likes" | "followers" | "comments" | "last_reacted_at"
|
||||
order_by: "rating" | "followers" | "comments" | "last_reacted_at"
|
||||
order_by_desc: true
|
||||
|
||||
}
|
||||
@@ -189,7 +186,7 @@ async def load_shouts_by(_, _info, options):
|
||||
# order
|
||||
order_by = Shout.featured_at if filters.get("featured") else Shout.published_at
|
||||
order_str = options.get("order_by")
|
||||
if order_str in ["likes", "followers", "comments", "last_reacted_at"]:
|
||||
if order_str in ["rating", "followers", "comments", "last_reacted_at"]:
|
||||
q = q.order_by(desc(text(f"{order_str}_stat")))
|
||||
query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
|
||||
q = q.order_by(nulls_last(query_order_by))
|
||||
@@ -203,10 +200,8 @@ async def load_shouts_by(_, _info, options):
|
||||
with local_session() as session:
|
||||
for [
|
||||
shout,
|
||||
reacted_stat,
|
||||
commented_stat,
|
||||
likes_stat,
|
||||
dislikes_stat,
|
||||
rating_stat,
|
||||
last_reacted_at,
|
||||
] in session.execute(q).unique():
|
||||
main_topic = (
|
||||
@@ -225,10 +220,9 @@ async def load_shouts_by(_, _info, options):
|
||||
if main_topic:
|
||||
shout.main_topic = main_topic[0]
|
||||
shout.stat = {
|
||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||
"reacted": reacted_stat,
|
||||
# "viewed": await ViewedStorage.get_shout(shout.slug),
|
||||
"commented": commented_stat,
|
||||
"rating": int(likes_stat) - int(dislikes_stat),
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reacted_at,
|
||||
}
|
||||
shouts.append(shout)
|
||||
@@ -267,10 +261,8 @@ async def load_shouts_feed(_, info, options):
|
||||
|
||||
for [
|
||||
shout,
|
||||
reacted_stat,
|
||||
commented_stat,
|
||||
likes_stat,
|
||||
dislikes_stat,
|
||||
rating_stat,
|
||||
last_reacted_at,
|
||||
] in session.execute(q).unique():
|
||||
main_topic = (
|
||||
@@ -290,9 +282,8 @@ async def load_shouts_feed(_, info, options):
|
||||
shout.main_topic = main_topic[0]
|
||||
shout.stat = {
|
||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||
"reacted": reacted_stat,
|
||||
"commented": commented_stat,
|
||||
"rating": likes_stat - dislikes_stat,
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reacted_at,
|
||||
}
|
||||
shouts.append(shout)
|
||||
@@ -362,18 +353,15 @@ async def get_shouts_from_query(q, author_id=None):
|
||||
with local_session() as session:
|
||||
for [
|
||||
shout,
|
||||
reacted_stat,
|
||||
commented_stat,
|
||||
likes_stat,
|
||||
dislikes_stat,
|
||||
rating_stat,
|
||||
last_reacted_at,
|
||||
] in session.execute(q, {"author_id": author_id}).unique():
|
||||
shouts.append(shout)
|
||||
shout.stat = {
|
||||
"viewed": await ViewedStorage.get_shout(shout_slug=shout.slug),
|
||||
"reacted": reacted_stat,
|
||||
# "viewed": await ViewedStorage.get_shout(shout_slug=shout.slug),
|
||||
"commented": commented_stat,
|
||||
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reacted_at,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user