This commit is contained in:
parent
26b862d601
commit
33ddfc6c31
|
@ -1,6 +1,7 @@
|
||||||
#### [0.4.8]
|
#### [0.4.8]
|
||||||
- `Reaction.deleted_at` filter on `update_reaction` resolver added
|
- `Reaction.deleted_at` filter on `update_reaction` resolver added
|
||||||
- `triggers` module updated with `after_shout_handler`, `after_reaction_handler` for cache revalidation
|
- `triggers` module updated with `after_shout_handler`, `after_reaction_handler` for cache revalidation
|
||||||
|
- `after_shout_handler`, `after_reaction_handler` now also handle `deleted_at` field
|
||||||
|
|
||||||
#### [0.4.7]
|
#### [0.4.7]
|
||||||
- `get_my_rates_shouts` resolver added with:
|
- `get_my_rates_shouts` resolver added with:
|
||||||
|
|
47
cache/triggers.py
vendored
47
cache/triggers.py
vendored
|
@ -51,29 +51,44 @@ def after_shout_handler(mapper, connection, target):
|
||||||
# Проверяем изменение статуса публикации
|
# Проверяем изменение статуса публикации
|
||||||
was_published = target.published_at is not None and target.deleted_at is None
|
was_published = target.published_at is not None and target.deleted_at is None
|
||||||
|
|
||||||
if was_published:
|
# Всегда обновляем счетчики для авторов и тем при любом изменении поста
|
||||||
# Обновляем счетчики для авторов
|
for author in target.authors:
|
||||||
for author in target.authors:
|
revalidation_manager.mark_for_revalidation(author.id, "authors")
|
||||||
revalidation_manager.mark_for_revalidation(author.id, "authors")
|
|
||||||
|
for topic in target.topics:
|
||||||
# Обновляем счетчики для тем
|
revalidation_manager.mark_for_revalidation(topic.id, "topics")
|
||||||
for topic in target.topics:
|
|
||||||
revalidation_manager.mark_for_revalidation(topic.id, "topics")
|
# Обновляем сам пост
|
||||||
|
revalidation_manager.mark_for_revalidation(target.id, "shouts")
|
||||||
|
|
||||||
|
|
||||||
def after_reaction_handler(mapper, connection, target):
|
def after_reaction_handler(mapper, connection, target):
|
||||||
"""Обработчик для комментариев"""
|
"""Обработчик для комментариев"""
|
||||||
if not isinstance(target, Reaction) or target.kind != ReactionKind.COMMENT.value:
|
if not isinstance(target, Reaction):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Проверяем что комментарий относится к опубликованному посту
|
# Проверяем что это комментарий
|
||||||
|
is_comment = target.kind == ReactionKind.COMMENT.value
|
||||||
|
|
||||||
|
# Получаем связанный пост
|
||||||
shout = target.shout
|
shout = target.shout
|
||||||
if shout and shout.published_at and not shout.deleted_at:
|
if not shout:
|
||||||
# Обновляем счетчики для автора комментария
|
return
|
||||||
revalidation_manager.mark_for_revalidation(target.created_by.id, "authors")
|
|
||||||
|
|
||||||
# Обновляем счетчики для поста
|
# Обновляем счетчики для автора комментария
|
||||||
revalidation_manager.mark_for_revalidation(shout.id, "shouts")
|
if target.created_by:
|
||||||
|
revalidation_manager.mark_for_revalidation(target.created_by.id, "authors")
|
||||||
|
|
||||||
|
# Обновляем счетчики для поста и его авторов/тем
|
||||||
|
revalidation_manager.mark_for_revalidation(shout.id, "shouts")
|
||||||
|
|
||||||
|
if is_comment and shout.published_at and not shout.deleted_at:
|
||||||
|
# Для комментариев к опубликованным постам обновляем также:
|
||||||
|
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():
|
||||||
|
@ -98,8 +113,10 @@ def events_register():
|
||||||
event.listen(Author, "after_update", mark_for_revalidation)
|
event.listen(Author, "after_update", mark_for_revalidation)
|
||||||
event.listen(Topic, "after_update", mark_for_revalidation)
|
event.listen(Topic, "after_update", mark_for_revalidation)
|
||||||
event.listen(Shout, "after_update", after_shout_handler)
|
event.listen(Shout, "after_update", after_shout_handler)
|
||||||
|
event.listen(Shout, "after_delete", after_shout_handler)
|
||||||
|
|
||||||
event.listen(Reaction, "after_insert", after_reaction_handler)
|
event.listen(Reaction, "after_insert", after_reaction_handler)
|
||||||
|
event.listen(Reaction, "after_update", after_reaction_handler)
|
||||||
event.listen(Reaction, "after_delete", after_reaction_handler)
|
event.listen(Reaction, "after_delete", after_reaction_handler)
|
||||||
|
|
||||||
logger.info("Event handlers registered successfully.")
|
logger.info("Event handlers registered successfully.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user