From 543b2e6b4d0124cbd3d3e74454ac5aab3b471241 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 6 Jun 2024 11:13:54 +0300 Subject: [PATCH] load_shouts_unrated-fix --- resolvers/author.py | 2 +- resolvers/reader.py | 7 +++---- services/auth.py | 5 ++--- services/precache.py | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 0a238690..39b98517 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -10,10 +10,10 @@ from services.auth import login_required from services.cache import ( cache_author, get_cached_author, + get_cached_author_by_user_id, get_cached_author_followers, get_cached_follower_authors, get_cached_follower_topics, - get_cached_author_by_user_id ) from services.db import local_session from services.logger import root_logger as logger diff --git a/resolvers/reader.py b/resolvers/reader.py index ed839966..bb25c9db 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -1,6 +1,5 @@ -from sqlalchemy import bindparam, distinct, or_, text from sqlalchemy.orm import aliased, joinedload -from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select +from sqlalchemy.sql.expression import and_, asc, bindparam, case, desc, distinct, func, nulls_last, or_, select, text from orm.author import Author, AuthorFollower from orm.reaction import Reaction, ReactionKind @@ -329,12 +328,12 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0): q.outerjoin( Reaction, and_( - Reaction.shout == Shout.id, + Reaction.shout_id == Shout.id, Reaction.reply_to.is_(None), Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]), ), ) - .outerjoin(Author, Author.user == bindparam("user_id")) + .outerjoin(Author, and_(Author.user == bindparam("user_id"), Reaction.created_by == Author.id)) .where( and_( Shout.deleted_at.is_(None), diff --git a/services/auth.py b/services/auth.py index 5a1d5066..6b2de120 100644 --- a/services/auth.py +++ b/services/auth.py @@ -21,12 +21,11 @@ async def request_data(gql, headers=None): logger.error(f"HTTP Errors: {errors}") else: return data - except Exception as e: + except Exception as _e: # Handling and logging exceptions during authentication check import traceback - logger.error(f"request_data error: {e}") - logger.error(traceback.format_exc()) + logger.error(f"request_data error: {traceback.format_exc()}") return None diff --git a/services/precache.py b/services/precache.py index 26f4883e..4d45cee8 100644 --- a/services/precache.py +++ b/services/precache.py @@ -128,7 +128,7 @@ async def precache_data(): for author in authors: profile = author.dict() if not isinstance(author, dict) else author author_id = profile.get("id") - user_id = profile.get("user","").strip() + user_id = profile.get("user", "").strip() if author_id and user_id: authors_by_id[author_id] = profile await cache_author(profile)