aifix
All checks were successful
Deploy on push / deploy (push) Successful in 1m28s

This commit is contained in:
Untone 2024-06-04 11:51:39 +03:00
parent 708bdaa7f6
commit db2ae09ead
2 changed files with 24 additions and 21 deletions

View File

@ -16,9 +16,9 @@ starlette = "^0.37.2"
gql = "^3.5.0" gql = "^3.5.0"
ariadne = "^0.23.0" ariadne = "^0.23.0"
pre-commit = "^3.7.0" pre-commit = "^3.7.0"
granian = "^1.2.1" granian = "^1.4.1"
google-analytics-data = "^0.18.7" google-analytics-data = "^0.18.7"
opensearch-py = "^2.5.0" opensearch-py = "^2.6.0"
httpx = "^0.27.0" httpx = "^0.27.0"
dogpile-cache = "^1.3.1" dogpile-cache = "^1.3.1"
colorlog = "^6.8.2" colorlog = "^6.8.2"

View File

@ -13,33 +13,36 @@ from services.logger import root_logger as logger
def add_topic_stat_columns(q): def add_topic_stat_columns(q):
aliased_shout = aliased(ShoutTopic) aliased_shout = aliased(ShoutTopic)
# Соединяем таблицу Topic с таблицами ShoutTopic и Shout, используя INNER JOIN # Create a new query object
q = ( new_q = select(Topic)
q.select_from(Topic)
.join( # Apply the necessary filters to the new query object
aliased_shout, new_q = new_q.join(
aliased_shout.topic == Topic.id, aliased_shout,
) aliased_shout.topic == Topic.id,
.join( ).join(
Shout, Shout,
and_( and_(
aliased_shout.shout == Shout.id, aliased_shout.shout == Shout.id,
Shout.deleted_at.is_(None), Shout.deleted_at.is_(None),
), ),
) ).add_columns(
.add_columns(func.count(distinct(aliased_shout.shout)).label("shouts_stat")) func.count(distinct(aliased_shout.shout)).label("shouts_stat")
) )
aliased_follower = aliased(TopicFollower) aliased_follower = aliased(TopicFollower)
# Соединяем таблицу Topic с таблицей TopicFollower, используя LEFT OUTER JOIN new_q = new_q.outerjoin(
q = q.outerjoin(aliased_follower, aliased_follower.topic == Topic.id).add_columns( aliased_follower,
aliased_follower.topic == Topic.id
).add_columns(
func.count(distinct(aliased_follower.follower)).label("followers_stat") 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): def add_author_stat_columns(q):