diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 343b544a..9e30f519 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -207,7 +207,8 @@ async def create_reaction(_, info, reaction): info.context.get("user_id") author_id = info.context.get("author", {}).get("id") shout_id = reaction.get("shout") - + if not author_id: + return {"error": "Unauthorized"} if not shout_id: return {"error": "Shout ID is required to create a reaction."} diff --git a/services/search.py b/services/search.py index 391556ae..512f8c88 100644 --- a/services/search.py +++ b/services/search.py @@ -20,7 +20,10 @@ REDIS_TTL = 86400 # 1 день в секундах index_settings = { "settings": { - "index": {"number_of_shards": 1, "auto_expand_replicas": "0-all"}, + "index": { + "number_of_shards": 1, + "auto_expand_replicas": "0-all" + }, "analysis": { "analyzer": { "ru": { @@ -37,13 +40,13 @@ index_settings = { "mappings": { "properties": { "body": {"type": "text", "analyzer": "ru"}, - #"cover": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, - #"created_at": {"type": "long"}, - #"created_by": {"type": "long"}, - #"featured_at": {"type": "long"}, - #"id": {"type": "long"}, - #"lang": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, - #"layout": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, + # "cover": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, + # "created_at": {"type": "long"}, + # "created_by": {"type": "long"}, + # "featured_at": {"type": "long"}, + # "id": {"type": "long"}, + # "lang": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, + # "layout": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, "lead": {"type": "text", "analyzer": "ru"}, "media": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, # "oid": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, diff --git a/services/triggers.py b/services/triggers.py index 76a5267e..76d5f273 100644 --- a/services/triggers.py +++ b/services/triggers.py @@ -94,9 +94,8 @@ def after_reaction_update(mapper, connection, reaction: Reaction): for author_with_stat in get_with_stat(author_query): asyncio.create_task(cache_author(author_with_stat.dict())) - shout = connection.execute( - select(Shout).select_from(Shout).where(Shout.id == reaction.shout) - ).first() + shout_query = select(Shout).select_from(Shout).where(Shout.id == reaction.shout) + [shout] = connection.execute(shout_query) if shout: after_shout_update(mapper, connection, shout) except Exception as exc: