fix-revalidation2
All checks were successful
Deploy on push / deploy (push) Successful in 58s

This commit is contained in:
Untone 2025-02-04 00:08:25 +03:00
parent 84de0c5538
commit 747d550d80

21
cache/triggers.py vendored
View File

@ -6,6 +6,7 @@ from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout, ShoutAuthor, ShoutReactionsFollower
from orm.topic import Topic, TopicFollower
from utils.logger import root_logger as logger
from services.db import local_session
def mark_for_revalidation(entity, *args):
@ -71,19 +72,27 @@ def after_reaction_handler(mapper, connection, target):
is_comment = target.kind == ReactionKind.COMMENT.value
# Получаем связанный пост
shout = target.shout
if not shout:
shout_id = target.shout if isinstance(target.shout, int) else target.shout.id
if not shout_id:
return
# Обновляем счетчики для автора комментария
if target.created_by:
revalidation_manager.mark_for_revalidation(target.created_by, "authors")
# Обновляем счетчики для поста и его авторов/тем
revalidation_manager.mark_for_revalidation(shout.id, "shouts")
# Обновляем счетчики для поста
revalidation_manager.mark_for_revalidation(shout_id, "shouts")
if is_comment and shout.published_at and not shout.deleted_at:
# Для комментариев к опубликованным постам обновляем также:
if is_comment:
# Для комментариев обновляем также авторов и темы
with local_session() as session:
shout = session.query(Shout).filter(
Shout.id == shout_id,
Shout.published_at.is_not(None),
Shout.deleted_at.is_(None)
).first()
if shout:
for author in shout.authors:
revalidation_manager.mark_for_revalidation(author.id, "authors")