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