get_shout-fix
All checks were successful
Deploy on push / deploy (push) Successful in 1m12s

This commit is contained in:
Untone 2024-10-23 11:22:07 +03:00
parent 79ab0d6a4c
commit 23514ca5a4
5 changed files with 13 additions and 9 deletions

View File

@ -10,6 +10,7 @@
- invite status enum added - invite status enum added
- topic parents ids added - topic parents ids added
- community CUDL resolvers added - community CUDL resolvers added
- get_shout resolver accepts slug or shout_id
[0.4.4] [0.4.4]
- followers_stat removed for shout - followers_stat removed for shout

6
cache/precache.py vendored
View File

@ -78,14 +78,14 @@ async def precache_topics_followers(topic_id: int, session):
async def precache_data(): async def precache_data():
logger.info("precaching...") logger.info("precaching...")
try: try:
key = "authorizer_dev" key = "authorizer_env"
# cache reset # cache reset
value = await redis.get(key) value = await redis.execute("HGET", key)
await redis.execute("FLUSHDB") await redis.execute("FLUSHDB")
logger.info("redis: FLUSHDB") logger.info("redis: FLUSHDB")
if value is not None: if value is not None:
await redis.execute("HSET", key, value) await redis.execute("HSET", key, value)
logger.info(f"Значение ключа '{key}' сохранено") logger.info(f"redis hash '{key}' was successfully restored")
with local_session() as session: with local_session() as session:
# topics # topics

View File

@ -35,7 +35,7 @@ async def cache_by_id(entity, entity_id: int, cache_method):
@query.field("get_my_shout") @query.field("get_my_shout")
@login_required @login_required
async def get_my_shout(_, info, shout_id: int): async def get_my_shout(_, info, shout_id: int):
logger.debug(info) # logger.debug(info)
user_id = info.context.get("user_id", "") user_id = info.context.get("user_id", "")
author_dict = info.context.get("author", {}) author_dict = info.context.get("author", {})
author_id = author_dict.get("id") author_id = author_dict.get("id")
@ -54,7 +54,7 @@ async def get_my_shout(_, info, shout_id: int):
if not shout: if not shout:
return {"error": "no shout found", "shout": None} return {"error": "no shout found", "shout": None}
logger.debug(f"got shout authors: {shout.authors} created by {shout.created_by}") logger.debug(f"got {len(shout.authors)} shout authors, created by {shout.created_by}")
is_editor = "editor" in roles is_editor = "editor" in roles
logger.debug(f'viewer is{'' if is_editor else ' not'} editor') logger.debug(f'viewer is{'' if is_editor else ' not'} editor')
is_creator = author_id == shout.created_by is_creator = author_id == shout.created_by

View File

@ -27,12 +27,13 @@ from services.viewed import ViewedStorage
from utils.logger import root_logger as logger from utils.logger import root_logger as logger
def query_shouts(slug=None): def query_shouts(slug=None, shout_id=None):
""" """
Базовый запрос для получения публикаций с подзапросами статистики, авторов и тем, Базовый запрос для получения публикаций с подзапросами статистики, авторов и тем,
с агрегацией в строку. с агрегацией в строку.
:param slug: Опциональный параметр для фильтрации по slug. :param slug: Опциональный параметр для фильтрации по slug.
:param shout_id: Опциональный параметр для фильтрации по shout_id.
:return: Запрос для получения публикаций, aliased_reaction: :return: Запрос для получения публикаций, aliased_reaction:
""" """
aliased_reaction = aliased(Reaction) aliased_reaction = aliased(Reaction)
@ -143,6 +144,8 @@ def query_shouts(slug=None):
if slug: if slug:
q = q.where(Shout.slug == slug) q = q.where(Shout.slug == slug)
elif shout_id:
q = q.where(Shout.id == shout_id)
return q, aliased_reaction return q, aliased_reaction
@ -311,7 +314,7 @@ def apply_filters(q, filters, author_id=None):
@query.field("get_shout") @query.field("get_shout")
async def get_shout(_, info, slug: str): async def get_shout(_, info, slug: str, shout_id: int):
""" """
Получение публикации по slug. Получение публикации по slug.
@ -324,7 +327,7 @@ async def get_shout(_, info, slug: str):
with local_session() as session: with local_session() as session:
# Отключение автосохранения # Отключение автосохранения
with session.no_autoflush: with session.no_autoflush:
q, aliased_reaction = query_shouts(slug) q, _ = query_shouts(slug)
results = session.execute(q).first() results = session.execute(q).first()
if results: if results:
[ [

View File

@ -26,7 +26,7 @@ type Query {
load_reactions_by(by: ReactionBy!, limit: Int, offset: Int): [Reaction] load_reactions_by(by: ReactionBy!, limit: Int, offset: Int): [Reaction]
# reader # reader
get_shout(slug: String): Shout get_shout(slug: String, shout_id: Int): Shout
load_shouts_by(options: LoadShoutsOptions): [Shout] load_shouts_by(options: LoadShoutsOptions): [Shout]
load_shout_comments(shout: Int!, limit: Int, offset: Int): [Reaction] load_shout_comments(shout: Int!, limit: Int, offset: Int): [Reaction]
load_shout_ratings(shout: Int!, limit: Int, offset: Int): [Reaction] load_shout_ratings(shout: Int!, limit: Int, offset: Int): [Reaction]