diff --git a/pyproject.toml b/pyproject.toml index b1edc3bf..e615cc89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,9 +16,9 @@ starlette = "^0.37.2" gql = "^3.5.0" ariadne = "^0.23.0" pre-commit = "^3.7.0" -granian = "^1.2.1" +granian = "^1.4.1" google-analytics-data = "^0.18.7" -opensearch-py = "^2.5.0" +opensearch-py = "^2.6.0" httpx = "^0.27.0" dogpile-cache = "^1.3.1" colorlog = "^6.8.2" diff --git a/resolvers/stat.py b/resolvers/stat.py index 0f6aff33..6918440f 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -13,33 +13,36 @@ from services.logger import root_logger as logger def add_topic_stat_columns(q): aliased_shout = aliased(ShoutTopic) - # Соединяем таблицу Topic с таблицами ShoutTopic и Shout, используя INNER JOIN - q = ( - q.select_from(Topic) - .join( - aliased_shout, - aliased_shout.topic == Topic.id, - ) - .join( - Shout, - and_( - aliased_shout.shout == Shout.id, - Shout.deleted_at.is_(None), - ), - ) - .add_columns(func.count(distinct(aliased_shout.shout)).label("shouts_stat")) + # Create a new query object + new_q = select(Topic) + + # Apply the necessary filters to the new query object + new_q = new_q.join( + aliased_shout, + aliased_shout.topic == Topic.id, + ).join( + Shout, + and_( + aliased_shout.shout == Shout.id, + Shout.deleted_at.is_(None), + ), + ).add_columns( + func.count(distinct(aliased_shout.shout)).label("shouts_stat") ) aliased_follower = aliased(TopicFollower) - # Соединяем таблицу Topic с таблицей TopicFollower, используя LEFT OUTER JOIN - q = q.outerjoin(aliased_follower, aliased_follower.topic == Topic.id).add_columns( + new_q = new_q.outerjoin( + aliased_follower, + aliased_follower.topic == Topic.id + ).add_columns( func.count(distinct(aliased_follower.follower)).label("followers_stat") ) - q = q.group_by(Topic.id) + new_q = new_q.group_by(Topic.id) + + return new_q - return q def add_author_stat_columns(q):