get-shout-fix2
Some checks failed
Deploy on push / deploy (push) Failing after 9s

This commit is contained in:
Untone 2024-08-08 17:36:20 +03:00
parent 7bb70c41df
commit e46de27ba9
2 changed files with 6 additions and 12 deletions

View File

@ -27,10 +27,8 @@ def add_reaction_stat_columns(q, aliased_reaction):
""" """
# Присоединение реакций и добавление статистических колонок # Присоединение реакций и добавление статистических колонок
q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns( q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
# Подсчет комментариев # Подсчет комментариев
func.count(case((aliased_reaction.body.is_not(None), 1), else_=0)).label("comments_stat"), func.count(case((aliased_reaction.body.is_not(None), 1), else_=0)).label("comments_stat"),
# Вычисление рейтинга как разница между лайками и дизлайками # Вычисление рейтинга как разница между лайками и дизлайками
func.sum( func.sum(
case( case(
@ -497,13 +495,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
reactions = set() reactions = set()
with local_session() as session: with local_session() as session:
result_rows = session.execute(q) result_rows = session.execute(q)
for [ for [reaction, author, shout, commented_stat, rating_stat] in result_rows:
reaction,
author,
shout,
commented_stat,
rating_stat
] in result_rows:
reaction.created_by = author reaction.created_by = author
reaction.shout = shout reaction.shout = shout
reaction.stat = {"rating": rating_stat, "commented": commented_stat} reaction.stat = {"rating": rating_stat, "commented": commented_stat}

View File

@ -47,7 +47,7 @@ def query_shouts():
func.concat("slug:", Author.slug), func.concat("slug:", Author.slug),
func.concat("pic:", Author.pic), func.concat("pic:", Author.pic),
), ),
" | " " | ",
).label("authors"), # Используем символ | как разделитель ).label("authors"), # Используем символ | как разделитель
) )
.join(Author, ShoutAuthor.author == Author.id) .join(Author, ShoutAuthor.author == Author.id)
@ -67,7 +67,7 @@ def query_shouts():
func.concat("slug:", Topic.slug), func.concat("slug:", Topic.slug),
func.concat("is_main:", ShoutTopic.main), func.concat("is_main:", ShoutTopic.main),
), ),
" | " " | ",
).label("topics"), # Используем символ | как разделитель ).label("topics"), # Используем символ | как разделитель
) )
.join(Topic, ShoutTopic.topic == Topic.id) .join(Topic, ShoutTopic.topic == Topic.id)
@ -105,6 +105,7 @@ def query_shouts():
return q, aliased_reaction return q, aliased_reaction
def parse_aggregated_string(aggregated_str): def parse_aggregated_string(aggregated_str):
""" """
Преобразует строку, полученную из string_agg, обратно в список словарей. Преобразует строку, полученную из string_agg, обратно в список словарей.
@ -120,7 +121,7 @@ def parse_aggregated_string(aggregated_str):
for item_str in aggregated_str.split(" | "): for item_str in aggregated_str.split(" | "):
item_data = {} item_data = {}
for field in item_str.split(";"): for field in item_str.split(";"):
if ':' in field: if ":" in field:
key, value = field.split(":", 1) key, value = field.split(":", 1)
item_data[key] = value item_data[key] = value
else: else:
@ -325,6 +326,7 @@ async def get_shout(_, info, slug: str):
return shout return shout
except Exception as _exc: except Exception as _exc:
import traceback import traceback
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
return None return None