From 4848aeefc93cc483e4b2a524fc611c5b64c301b1 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 6 Feb 2023 16:15:47 +0300 Subject: [PATCH 1/2] [hotfix] add ID to updateReaction --- resolvers/zine/reactions.py | 9 +++++---- schema.graphql | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 071e5b38..4e9485e2 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -201,13 +201,14 @@ async def create_reaction(_, info, reaction={}): @mutation.field("updateReaction") @login_required -async def update_reaction(_, info, reaction={}): +async def update_reaction(_, info, id, reaction={}): auth: AuthCredentials = info.context["request"].auth with local_session() as session: user = session.query(User).where(User.id == auth.user_id).first() - q = select(Reaction).filter(Reaction.id == reaction['id']) + q = select(Reaction).filter(Reaction.id == id) q = add_reaction_stat_columns(q) + q = q.group_by(Reaction.id) [r, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one() @@ -235,12 +236,12 @@ async def update_reaction(_, info, reaction={}): @mutation.field("deleteReaction") @login_required -async def delete_reaction(_, info, reaction=None): +async def delete_reaction(_, info, id): # NOTE: reaction is id auth: AuthCredentials = info.context["request"].auth with local_session() as session: - r = session.query(Reaction).filter(Reaction.id == reaction).first() + r = session.query(Reaction).filter(Reaction.id == id).first() if not r: return {"error": "invalid reaction id"} if r.createdBy != auth.user_id: diff --git a/schema.graphql b/schema.graphql index 7f30b8ae..f780d0fb 100644 --- a/schema.graphql +++ b/schema.graphql @@ -198,8 +198,8 @@ type Mutation { # reactions createReaction(reaction: ReactionInput!): Result! - updateReaction(reaction: ReactionInput!): Result! - deleteReaction(reaction: Int!): Result! + updateReaction(id: Int!, reaction: ReactionInput!): Result! + deleteReaction(id: Int!): Result! # draft / collab createDraft(draft: DraftInput!): Result! From efbea09495afc94c099d27711fb176de445d4e96 Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Thu, 16 Feb 2023 11:30:35 +0100 Subject: [PATCH 2/2] fast random topics --- resolvers/zine/topics.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resolvers/zine/topics.py b/resolvers/zine/topics.py index a0cfa3e7..1eebdd60 100644 --- a/resolvers/zine/topics.py +++ b/resolvers/zine/topics.py @@ -145,8 +145,14 @@ def topic_unfollow(user_id, slug): @query.field("topicsRandom") async def topics_random(_, info, amount=12): q = select(Topic) - q = add_topic_stat_columns(q) + q = q.join(ShoutTopic) + q = q.group_by(Topic.id) q = q.having(func.count(distinct(ShoutTopic.shout)) > 2) q = q.order_by(func.random()).limit(amount) - return get_topics_from_query(q) + topics = [] + with local_session() as session: + for [topic] in session.execute(q): + topics.append(topic) + + return topics