From 4e7250acef07795c8e62ad4231d16d43b50150cc Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 24 Nov 2023 04:53:30 +0300 Subject: [PATCH] logs-fix --- CHANGELOG.txt | 1 + resolvers/author.py | 16 +++++++++++----- schemas/core.graphql | 4 ++-- services/notify.py | 21 ++++++--------------- services/search.py | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5c02d565..bdc3d0fa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ - services: cached elasticsearch connector - services: auth is using user_id from authorizer - resolvers: notify_* usage fixes +- resolvers: getAuthor now accepts slug, user_id or author_id - resolvers: login_required usage fixes [0.2.14] diff --git a/resolvers/author.py b/resolvers/author.py index 5df75e46..36a8b374 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -138,12 +138,18 @@ async def get_authors_all(_, _info): @query.field("getAuthor") -async def get_author(_, _info, slug): - q = select(Author).where(Author.slug == slug) - q = add_author_stat_columns(q) +async def get_author(_, _info, slug="", user=None, author=None): + if slug or user or author: + if slug: + q = select(Author).where(Author.slug == slug) + elif user: + q = select(Author).where(Author.user == user) + elif author: + q = select(Author).where(Author.id == author) + q = add_author_stat_columns(q) - authors = get_authors_from_query(q) - return authors[0] + authors = get_authors_from_query(q) + return authors[0] @query.field("loadAuthorsBy") diff --git a/schemas/core.graphql b/schemas/core.graphql index 7607f77b..ba932746 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -318,7 +318,7 @@ type Query { loadDrafts: [Shout] search(text: String!, limit: Int, offset: Int): [Shout] - + loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction] followedReactions(follower_id: Int!): [Shout] @@ -327,7 +327,7 @@ type Query { authorFollowedAuthors(slug: String!): [Author] authorFollowedTopics(slug: String!): [Topic] loadAuthorsBy(by: AuthorsBy, limit: Int, offset: Int): [Author] - getAuthor(slug: String!): Author + getAuthor(slug: String, user: String, author: Int): Author topicsAll: [Topic] getTopic(slug: String!): Topic diff --git a/services/notify.py b/services/notify.py index 1ca32827..8e721699 100644 --- a/services/notify.py +++ b/services/notify.py @@ -4,26 +4,20 @@ from services.rediscache import redis async def notify_reaction(reaction, action: str = "create"): channel_name = "reaction" - data = { - "payload": reaction, - "action": action - } + data = {"payload": reaction, "action": action} try: await redis.publish(channel_name, json.dumps(data)) except Exception as e: - print(f"Failed to publish to channel {channel_name}: {e}") + print(f"[services.notify] Failed to publish to channel {channel_name}: {e}") async def notify_shout(shout, action: str = "create"): channel_name = "shout" - data = { - "payload": shout, - "action": action - } + data = {"payload": shout, "action": action} try: await redis.publish(channel_name, json.dumps(data)) except Exception as e: - print(f"Failed to publish to channel {channel_name}: {e}") + print(f"[services.notify] Failed to publish to channel {channel_name}: {e}") async def notify_follower(follower: dict, author_id: int, action: str = "follow"): @@ -32,11 +26,8 @@ async def notify_follower(follower: dict, author_id: int, action: str = "follow" if k not in ["id", "name", "slug", "pic"]: del follower[k] channel_name = f"follower:{author_id}" - data = { - "payload": follower, - "action": action - } + data = {"payload": follower, "action": action} try: await redis.publish(channel_name, json.dumps(data)) except Exception as e: - print(f"Failed to publish to channel {channel_name}: {e}") + print(f"[services.notify] Failed to publish to channel {channel_name}: {e}") diff --git a/services/search.py b/services/search.py index 21b341eb..bf32996b 100644 --- a/services/search.py +++ b/services/search.py @@ -12,7 +12,7 @@ class SearchService: @staticmethod async def init(session): async with SearchService.lock: - print("[search] did nothing") + print("[services.search] did nothing") SearchService.cache = {} @staticmethod