int-id-fix
All checks were successful
Deploy on push / deploy (push) Successful in 5m45s

This commit is contained in:
Untone 2024-02-24 21:15:11 +03:00
parent 5e72a08e0f
commit d7c9622ffa
6 changed files with 21 additions and 24 deletions

View File

@ -45,7 +45,7 @@ def get_author(_, _info, slug='', author_id=None):
if bool(slug):
q = select(Author).where(Author.slug == slug)
if author_id:
q = select(Author).where(Author.id == int(author_id))
q = select(Author).where(Author.id == author_id)
[author, ] = get_authors_with_stat(q, ratings=True)
except Exception as exc:
@ -204,10 +204,8 @@ def get_author_followers(_, _info, slug: str):
q = (
select(author_alias)
.join(alias_author_authors, alias_author_authors.follower == int(author_alias.id))
.join(
alias_author_followers, alias_author_followers.author == int(author_alias.id)
)
.join(alias_author_authors, alias_author_authors.follower == author_alias.id)
.join(alias_author_followers, alias_author_followers.author == author_alias.id)
.filter(author_alias.slug == slug)
.add_columns(
func.count(distinct(alias_shout_author.shout)).label('shouts_stat'),

View File

@ -186,8 +186,8 @@ def author_unfollow(follower_id, slug):
def get_topic_followers(_, _info, slug: str, topic_id: int) -> List[Author]:
q = select(Author)
q = (
q.join(TopicFollower, TopicFollower.follower == int(Author.id))
.join(Topic, Topic.id == int(TopicFollower.topic))
q.join(TopicFollower, TopicFollower.follower == Author.id)
.join(Topic, Topic.id == TopicFollower.topic)
.filter(or_(Topic.slug == slug, Topic.id == topic_id))
)
return get_authors_with_stat(q)

View File

@ -351,8 +351,8 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
q = (
select(Reaction, Author, Shout)
.join(Author, Reaction.created_by == int(Author.id))
.join(Shout, Reaction.shout == int(Shout.id))
.join(Author, Reaction.created_by == Author.id)
.join(Shout, Reaction.shout == Shout.id)
)
# calculate counters
@ -430,7 +430,7 @@ async def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[S
# Shouts where follower reacted
q2 = (
select(Shout)
.join(Reaction, Reaction.shout_id == int(Shout.id))
.join(Reaction, Reaction.shout_id == Shout.id)
.options(joinedload(Shout.reactions), joinedload(Shout.authors))
.filter(Reaction.created_by == follower_id)
.group_by(Shout.id)

View File

@ -207,7 +207,7 @@ async def load_shouts_drafts(_, info):
with local_session() as session:
reader = session.query(Author).filter(Author.user == user_id).first()
if isinstance(reader, Author):
q = q.filter(Shout.created_by == int(reader.id))
q = q.filter(Shout.created_by == reader.id)
q = q.group_by(Shout.id)
for [shout] in session.execute(q).unique():
main_topic = (
@ -240,16 +240,16 @@ async def load_shouts_feed(_, info, options):
reader = session.query(Author).filter(Author.user == user_id).first()
if reader:
reader_followed_authors = select(AuthorFollower.author).where(
AuthorFollower.follower == int(reader.id)
AuthorFollower.follower == reader.id
)
reader_followed_topics = select(TopicFollower.topic).where(
TopicFollower.follower == int(reader.id)
TopicFollower.follower == reader.id
)
subquery = (
select(Shout.id)
.where(Shout.id == int(ShoutAuthor.shout))
.where(Shout.id == int(ShoutTopic.shout))
.where(Shout.id == ShoutAuthor.shout)
.where(Shout.id == ShoutTopic.shout)
.where(
(ShoutAuthor.author.in_(reader_followed_authors))
| (ShoutTopic.topic.in_(reader_followed_topics))

View File

@ -189,7 +189,7 @@ def author_follows_authors(author_id: int):
def author_follows_topics(author_id: int):
q = (
select(Topic).select_from(
join(Topic, TopicFollower, Topic.id == int(TopicFollower.topic))
join(Topic, TopicFollower, Topic.id == TopicFollower.topic)
).where(TopicFollower.follower == author_id)
)

View File

@ -31,7 +31,7 @@ def after_shouts_update(mapper, connection, shout: Shout):
subquery = (
select(1)
.where(or_(
Author.id == int(shout.created_by),
Author.id == shout.created_by,
and_(
Shout.id == shout.id,
ShoutAuthor.shout == Shout.id,
@ -43,8 +43,8 @@ def after_shouts_update(mapper, connection, shout: Shout):
# Основной запрос с использованием объединения и подзапроса exists
authors_query = (
select(Author)
.join(ShoutAuthor, Author.id == int(ShoutAuthor.author))
.where(ShoutAuthor.shout == int(shout.id))
.join(ShoutAuthor, Author.id == ShoutAuthor.author)
.where(ShoutAuthor.shout == shout.id)
.union(
select(Author)
.where(exists(subquery))
@ -59,12 +59,12 @@ def after_shouts_update(mapper, connection, shout: Shout):
def after_reaction_insert(mapper, connection, reaction: Reaction):
author_subquery = (
select(Author)
.where(Author.id == int(reaction.created_by))
.where(Author.id == reaction.created_by)
)
replied_author_subquery = (
select(Author)
.join(Reaction, Author.id == int(Reaction.created_by))
.where(Reaction.id == int(reaction.reply_to))
.join(Reaction, Author.id == Reaction.created_by)
.where(Reaction.id == reaction.reply_to)
)
author_query = author_subquery.union(replied_author_subquery)
@ -73,12 +73,11 @@ def after_reaction_insert(mapper, connection, reaction: Reaction):
for author in authors:
asyncio.create_task(update_author_cache(author))
shout = connection.execute(select(Shout).where(Shout.id == int(reaction.shout))).first()
shout = connection.execute(select(Shout).where(Shout.id == reaction.shout)).first()
if shout:
after_shouts_update(mapper, connection, shout)
@event.listens_for(Author, 'after_insert')
@event.listens_for(Author, 'after_update')
def after_author_update(mapper, connection, author: Author):