events-trigger-query-fix
All checks were successful
Deploy on push / deploy (push) Successful in 25s
All checks were successful
Deploy on push / deploy (push) Successful in 25s
This commit is contained in:
parent
b02b8276a6
commit
5ca072dfaa
|
@ -81,8 +81,7 @@ def create_shout(_, info, inp):
|
|||
# NOTE: requesting new shout back
|
||||
shout = session.query(Shout).where(Shout.slug == slug).first()
|
||||
if shout:
|
||||
shout_dict = shout.dict()
|
||||
sa = ShoutAuthor(shout=shout.id, author=author.id)
|
||||
sa = ShoutAuthor(shout=shout.id, author=author.id, auto=True)
|
||||
session.add(sa)
|
||||
|
||||
topics = (
|
||||
|
@ -94,6 +93,8 @@ def create_shout(_, info, inp):
|
|||
t = ShoutTopic(topic=topic.id, shout=shout.id)
|
||||
session.add(t)
|
||||
|
||||
session.commit()
|
||||
|
||||
reactions_follow(author.id, shout.id, True)
|
||||
|
||||
# notifier
|
||||
|
|
|
@ -43,15 +43,19 @@ def add_author_stat_columns(q):
|
|||
aliased_author_authors = aliased(AuthorFollower)
|
||||
aliased_author_followers = aliased(AuthorFollower)
|
||||
|
||||
aliased_reaction = aliased(Reaction)
|
||||
|
||||
q = (
|
||||
q.outerjoin(aliased_shout_author, aliased_shout_author.author == Author.id)
|
||||
.add_columns(
|
||||
func.count(distinct(aliased_shout_author.shout)).label('shouts_stat')
|
||||
)
|
||||
|
||||
.outerjoin(aliased_author_authors, aliased_author_authors.follower == Author.id)
|
||||
.add_columns(
|
||||
func.count(distinct(aliased_author_authors.author)).label('authors_stat')
|
||||
)
|
||||
|
||||
.outerjoin(
|
||||
aliased_author_followers, aliased_author_followers.author == Author.id
|
||||
)
|
||||
|
@ -60,6 +64,18 @@ def add_author_stat_columns(q):
|
|||
'followers_stat'
|
||||
)
|
||||
)
|
||||
|
||||
.outerjoin(aliased_reaction)
|
||||
.add_columns(
|
||||
func.count(distinct(aliased_reaction.id)).filter(
|
||||
and_(
|
||||
aliased_reaction.created_by == Author.id,
|
||||
aliased_reaction.kind == ReactionKind.COMMENT.value,
|
||||
aliased_reaction.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
.label('comments_count')
|
||||
)
|
||||
)
|
||||
|
||||
q = q.group_by(Author.id)
|
||||
|
@ -138,9 +154,9 @@ def get_with_stat(q):
|
|||
with local_session() as session:
|
||||
for cols in session.execute(q):
|
||||
entity = cols[0]
|
||||
entity.stat = {'shouts': cols[1], 'authors': cols[2], 'followers': cols[3]}
|
||||
entity.stat = {'shouts': cols[1], 'authors': cols[2], 'followers': cols[3], 'comments': cols[4]}
|
||||
if is_author:
|
||||
# entity.stat['comments'] = cols[4]
|
||||
# entity.stat[
|
||||
# entity.stat['rating'] = cols[5] - cols[6]
|
||||
# entity.stat['rating_shouts'] = cols[7] - cols[8]
|
||||
pass
|
||||
|
|
|
@ -5,7 +5,7 @@ type AuthorStat {
|
|||
rating: Int
|
||||
rating_shouts: Int
|
||||
rating_comments: Int
|
||||
commented: Int
|
||||
comments: Int
|
||||
viewed: Int
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ type TopicStat {
|
|||
shouts: Int!
|
||||
followers: Int!
|
||||
authors: Int!
|
||||
viewed: Int
|
||||
comments: Int
|
||||
}
|
||||
|
||||
type Topic {
|
||||
|
|
|
@ -60,7 +60,7 @@ class Base(declarative_base()):
|
|||
|
||||
|
||||
make_searchable(Base.metadata)
|
||||
Base.metadata.create_all(engine)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
# Функция для вывода полного трейсбека при предупреждениях
|
||||
|
|
|
@ -35,13 +35,14 @@ def after_shouts_update(mapper, connection, shout: Shout):
|
|||
Shout.id == shout.id,
|
||||
ShoutAuthor.shout == Shout.id,
|
||||
ShoutAuthor.author == Author.id,
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# Основной запрос с использованием объединения и подзапроса exists
|
||||
authors_query = (
|
||||
select(Author)
|
||||
.select_from(Author)
|
||||
.join(ShoutAuthor, Author.id == ShoutAuthor.author)
|
||||
.where(ShoutAuthor.shout == shout.id)
|
||||
.union(select(Author).where(exists(subquery)))
|
||||
|
@ -56,6 +57,7 @@ def after_reaction_insert(mapper, connection, reaction: Reaction):
|
|||
author_subquery = select(Author).where(Author.id == reaction.created_by)
|
||||
replied_author_subquery = (
|
||||
select(Author)
|
||||
.select_from(Author)
|
||||
.join(Reaction, Author.id == Reaction.created_by)
|
||||
.where(Reaction.id == reaction.reply_to)
|
||||
)
|
||||
|
|
|
@ -34,7 +34,7 @@ class WebhookEndpoint(HTTPEndpoint):
|
|||
)
|
||||
if author:
|
||||
slug = slug + '-' + user_id.split('-').pop()
|
||||
await create_author(user_id, slug, name)
|
||||
create_author(user_id, slug, name)
|
||||
|
||||
return JSONResponse({'status': 'success'})
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user