From 13e7aaba011eb461f56a154df7b9d07d75f0208d Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Thu, 20 Apr 2023 21:01:41 +0800 Subject: [PATCH] Optimise alert groups private api endpoint (#1802) # What this PR does ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- engine/apps/api/views/alert_group.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 96420041..5a28e006 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -192,7 +192,7 @@ class AlertGroupFilter(DateRangeFilterMixin, ByTeamModelFieldFilterMixin, ModelF class AlertGroupTeamFilteringMixin(TeamFilteringMixin): - TEAM_LOOKUP = "channel__team" + TEAM_LOOKUP = "team" def retrieve(self, request, *args, **kwargs): try: @@ -283,19 +283,19 @@ class AlertGroupView( def get_queryset(self, ignore_filtering_by_available_teams=False): # no select_related or prefetch_related is used at this point, it will be done on paginate_queryset. - alert_receive_channels_ids = list( - AlertReceiveChannel.objects.filter( - organization_id=self.request.auth.organization.id, - ).values_list("id", flat=True) + + alert_receive_channels_qs = AlertReceiveChannel.objects.filter( + organization_id=self.request.auth.organization.id ) + if not ignore_filtering_by_available_teams: + alert_receive_channels_qs = alert_receive_channels_qs.filter(*self.available_teams_lookup_args) + + alert_receive_channels_ids = list(alert_receive_channels_qs.values_list("id", flat=True)) queryset = AlertGroup.unarchived_objects.filter( channel__in=alert_receive_channels_ids, ) - if not ignore_filtering_by_available_teams: - queryset = queryset.filter(*self.available_teams_lookup_args).distinct() - queryset = queryset.only("id") return queryset