This commit is contained in:
parent
84de0c5538
commit
747d550d80
29
cache/triggers.py
vendored
29
cache/triggers.py
vendored
|
@ -6,6 +6,7 @@ from orm.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutReactionsFollower
|
from orm.shout import Shout, ShoutAuthor, ShoutReactionsFollower
|
||||||
from orm.topic import Topic, TopicFollower
|
from orm.topic import Topic, TopicFollower
|
||||||
from utils.logger import root_logger as logger
|
from utils.logger import root_logger as logger
|
||||||
|
from services.db import local_session
|
||||||
|
|
||||||
|
|
||||||
def mark_for_revalidation(entity, *args):
|
def mark_for_revalidation(entity, *args):
|
||||||
|
@ -71,24 +72,32 @@ def after_reaction_handler(mapper, connection, target):
|
||||||
is_comment = target.kind == ReactionKind.COMMENT.value
|
is_comment = target.kind == ReactionKind.COMMENT.value
|
||||||
|
|
||||||
# Получаем связанный пост
|
# Получаем связанный пост
|
||||||
shout = target.shout
|
shout_id = target.shout if isinstance(target.shout, int) else target.shout.id
|
||||||
if not shout:
|
if not shout_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Обновляем счетчики для автора комментария
|
# Обновляем счетчики для автора комментария
|
||||||
if target.created_by:
|
if target.created_by:
|
||||||
revalidation_manager.mark_for_revalidation(target.created_by, "authors")
|
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:
|
||||||
# Для комментариев к опубликованным постам обновляем также:
|
# Для комментариев обновляем также авторов и темы
|
||||||
for author in shout.authors:
|
with local_session() as session:
|
||||||
revalidation_manager.mark_for_revalidation(author.id, "authors")
|
shout = session.query(Shout).filter(
|
||||||
|
Shout.id == shout_id,
|
||||||
|
Shout.published_at.is_not(None),
|
||||||
|
Shout.deleted_at.is_(None)
|
||||||
|
).first()
|
||||||
|
|
||||||
for topic in shout.topics:
|
if shout:
|
||||||
revalidation_manager.mark_for_revalidation(topic.id, "topics")
|
for author in shout.authors:
|
||||||
|
revalidation_manager.mark_for_revalidation(author.id, "authors")
|
||||||
|
|
||||||
|
for topic in shout.topics:
|
||||||
|
revalidation_manager.mark_for_revalidation(topic.id, "topics")
|
||||||
|
|
||||||
|
|
||||||
def events_register():
|
def events_register():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user