caching-fix
Some checks failed
Deploy on push / deploy (push) Failing after 9s

This commit is contained in:
2024-08-06 18:53:25 +03:00
parent 522718f3a1
commit b823862cec
3 changed files with 75 additions and 59 deletions

View File

@@ -21,14 +21,13 @@ from services.viewed import ViewedStorage
def add_reaction_stat_columns(q, aliased_reaction):
q = q.outerjoin(
aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
func.sum(aliased_reaction.id).label("reacted_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.COMMENT.value), 1), else_=0)).label("comments_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.LIKE.value), 1), else_=0)).label("likes_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.DISLIKE.value), 1), else_=0)).label("dislikes_stat"),
func.max(aliased_reaction.created_at).label("last_comment_stat")
)
q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
func.sum(aliased_reaction.id).label("reacted_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.COMMENT.value), 1), else_=0)).label("comments_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.LIKE.value), 1), else_=0)).label("likes_stat"),
func.sum(case((aliased_reaction.kind == str(ReactionKind.DISLIKE.value), 1), else_=0)).label("dislikes_stat"),
func.max(aliased_reaction.created_at).label("last_comment_stat"),
)
return q
@@ -427,7 +426,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
"reacted": reacted_stat,
"commented": commented_stat,
"last_reacted_at": last_reacted_at
"last_reacted_at": last_reacted_at,
}
reactions.add(reaction)

View File

@@ -30,6 +30,7 @@ def query_shouts():
select(Shout)
.options(joinedload(Shout.authors), joinedload(Shout.topics))
.where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None)))
.execution_options(populate_existing=True)
)
@@ -37,9 +38,11 @@ def filter_my(info, session, q):
user_id = info.context.get("user_id")
reader_id = info.context.get("author", {}).get("id")
if user_id and reader_id:
# Предварительный расчет ID для автора и темы
reader_followed_authors = select(AuthorFollower.author).where(AuthorFollower.follower == reader_id)
reader_followed_topics = select(TopicFollower.topic).where(TopicFollower.follower == reader_id)
# Используйте подзапросы для фильтрации
subquery = (
select(Shout.id)
.where(Shout.id == ShoutAuthor.shout)