More accurate invalidating of alert group web cache (#277)

* Disable invalidate ag web cache on user save

* Tweak invalidate_ag_web_cache on AlertReceiveChannel save
This commit is contained in:
Innokentii Konstantinov 2022-07-22 14:58:27 +04:00 committed by GitHub
parent 6b456f9820
commit 5205ceeede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

View file

@ -694,14 +694,19 @@ def listen_for_alertreceivechannel_model_save(sender, instance, created, *args,
instance.organization, None, OrganizationLogType.TYPE_HEARTBEAT_CREATED, description
)
else:
logger.info(f"Drop AG cache. Reason: save alert_receive_channel {instance.pk}")
if kwargs is not None:
if "update_fields" in kwargs:
if kwargs["update_fields"] is not None:
fields_to_not_to_invalidate_cache = [
"rate_limit_message_task_id",
"rate_limited_in_slack_at",
"reason_to_skip_escalation",
]
# Hack to not to invalidate web cache on AlertReceiveChannel.start_send_rate_limit_message_task
if "rate_limit_message_task_id" in kwargs["update_fields"]:
return
for f in fields_to_not_to_invalidate_cache:
if f in kwargs["update_fields"]:
return
logger.info(f"Drop AG cache. Reason: save alert_receive_channel {instance.pk}")
invalidate_web_cache_for_alert_group.apply_async(kwargs={"channel_pk": instance.pk})
if instance.integration == AlertReceiveChannel.INTEGRATION_GRAFANA_ALERTING:

View file

@ -8,7 +8,6 @@ from django.db.models.signals import post_save
from django.dispatch import receiver
from emoji import demojize
from apps.alerts.tasks import invalidate_web_cache_for_alert_group
from apps.schedules.tasks import drop_cached_ical_for_custom_events_for_organization
from common.constants.role import Role
from common.public_primary_keys import generate_public_primary_key, increase_public_primary_key_length
@ -255,14 +254,6 @@ class User(models.Model):
# TODO: check whether this signal can be moved to save method of the model
@receiver(post_save, sender=User)
def listen_for_user_model_save(sender, instance, created, *args, **kwargs):
# if kwargs is not None:
# if "update_fields" in kwargs:
# if kwargs["update_fields"] is not None:
# if "username" not in kwargs["update_fields"]:
# return
drop_cached_ical_for_custom_events_for_organization.apply_async(
(instance.organization_id,),
)
logger.info(f"Drop AG cache. Reason: save user {instance.pk}")
invalidate_web_cache_for_alert_group.apply_async(kwargs={"org_pk": instance.organization_id})