diff --git a/engine/apps/alerts/models/alert_group.py b/engine/apps/alerts/models/alert_group.py index d93f4f72b6..8eea0c0e23 100644 --- a/engine/apps/alerts/models/alert_group.py +++ b/engine/apps/alerts/models/alert_group.py @@ -511,17 +511,8 @@ def slack_app_link(self) -> typing.Optional[str]: @property def telegram_permalink(self) -> typing.Optional[str]: - """ - This property will attempt to access an attribute, `prefetched_telegram_messages`, representing a list of - prefetched telegram messages. If this attribute does not exist, it falls back to performing a query. - - See `apps.public_api.serializers.incidents.IncidentSerializer.PREFETCH_RELATED` as an example. - """ from apps.telegram.models.message import TelegramMessage - if hasattr(self, "prefetched_telegram_messages"): - return self.prefetched_telegram_messages[0].link if self.prefetched_telegram_messages else None - main_telegram_message = self.telegram_messages.filter( chat_id__startswith="-", message_type=TelegramMessage.ALERT_GROUP_MESSAGE ).first() diff --git a/engine/apps/public_api/serializers/incidents.py b/engine/apps/public_api/serializers/incidents.py index 90cf4abf15..1633b98430 100644 --- a/engine/apps/public_api/serializers/incidents.py +++ b/engine/apps/public_api/serializers/incidents.py @@ -1,8 +1,6 @@ -from django.db.models import Prefetch from rest_framework import serializers from apps.alerts.models import AlertGroup -from apps.telegram.models.message import TelegramMessage from common.api_helpers.custom_fields import UserIdField from common.api_helpers.mixins import EagerLoadingMixin @@ -19,14 +17,6 @@ class IncidentSerializer(EagerLoadingMixin, serializers.ModelSerializer): resolved_by = UserIdField(read_only=True, source="resolved_by_user") SELECT_RELATED = ["channel", "channel_filter", "slack_message", "channel__organization"] - PREFETCH_RELATED = [ - "alerts", - Prefetch( - "telegram_messages", - TelegramMessage.objects.filter(chat_id__startswith="-", message_type=TelegramMessage.ALERT_GROUP_MESSAGE), - to_attr="prefetched_telegram_messages", - ), - ] class Meta: model = AlertGroup @@ -50,7 +40,7 @@ def get_title(self, obj): return obj.web_title_cache def get_alerts_count(self, obj): - return len(obj.alerts.all()) + return obj.alerts.count() def get_state(self, obj): return obj.state