diff --git a/resolvers/follower.py b/resolvers/follower.py index 96d54b19..3c3a61b2 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -74,8 +74,8 @@ async def follow(_, info, what, slug): await cache_topic(topic_dict) elif what == "COMMUNITY": - # FIXME: when more communities - follows = local_session().execute(select(Community)) + with local_session() as session: + follows = session.execute(select(Community)) elif what == "SHOUT": error = reactions_follow(follower_id, slug) @@ -124,7 +124,8 @@ async def unfollow(_, info, what, slug): await cache_topic(topic_dict) elif what == "COMMUNITY": - follows = local_session().execute(select(Community)) + with local_session() as session: + follows = session.execute(select(Community)) elif what == "SHOUT": error = reactions_unfollow(follower_id, slug) diff --git a/resolvers/reader.py b/resolvers/reader.py index 66788752..2caa5412 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -327,7 +327,7 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0): Reaction, and_( Reaction.shout == Shout.id, - Reaction.replyTo.is_(None), + Reaction.reply_to.is_(None), Reaction.kind.in_( [ReactionKind.LIKE.value, ReactionKind.DISLIKE.value] ), diff --git a/resolvers/stat.py b/resolvers/stat.py index 88003328..79fa23e7 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -52,7 +52,8 @@ def get_topic_shouts_stat(topic_id: int): ) ) ) - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0 @@ -71,8 +72,9 @@ def get_topic_authors_stat(topic_id: int): ) # Выполняем запрос и получаем результат - result = local_session().execute(count_query).scalar() - return result if result is not None else 0 + with local_session() as session: + result = session.execute(count_query).first() + return result[0] if result else 0 def get_topic_followers_stat(topic_id: int): @@ -80,7 +82,8 @@ def get_topic_followers_stat(topic_id: int): q = select(func.count(distinct(aliased_followers.follower))).filter( aliased_followers.topic == topic_id ) - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0 @@ -107,8 +110,8 @@ def get_topic_comments_stat(topic_id: int): ShoutTopic.topic == topic_id ) q = q.outerjoin(sub_comments, ShoutTopic.shout == sub_comments.c.shout_id) - - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0 @@ -142,7 +145,8 @@ def get_author_authors_stat(author_id: int): aliased_authors.author != author_id, ) ) - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0 @@ -151,7 +155,8 @@ def get_author_followers_stat(author_id: int): q = select(func.count(distinct(aliased_followers.follower))).filter( aliased_followers.author == author_id ) - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0 @@ -173,8 +178,8 @@ def get_author_comments_stat(author_id: int): .subquery() ) q = select(sub_comments.c.comments_count).filter(sub_comments.c.id == author_id) - - result = local_session().execute(q).first() + with local_session() as session: + result = session.execute(q).first() return result[0] if result else 0