diff --git a/resolvers/author.py b/resolvers/author.py index a2f1028f..f3ecfee5 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -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'), diff --git a/resolvers/follower.py b/resolvers/follower.py index 6c41a6ec..0bc36273 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -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) diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 94a7f601..72a758f3 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -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) diff --git a/resolvers/reader.py b/resolvers/reader.py index 43192a99..ff7cffff 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -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)) diff --git a/resolvers/stat.py b/resolvers/stat.py index 134627c5..b3d31ea3 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -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) ) diff --git a/services/event_listeners.py b/services/event_listeners.py index 6200fd6b..6c1126ef 100644 --- a/services/event_listeners.py +++ b/services/event_listeners.py @@ -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):