From 44484b56f1e26cda16c19dd4a303ba9b59847948 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Wed, 6 Dec 2023 13:10:56 +0000 Subject: [PATCH] Modify alert group list index (#3502) # What this PR does Modifies the database index used by the alert group list page to accommodate ordering by [`-started_at`](https://github.com/grafana/oncall/pull/3502/files#diff-68d8b0b2e9b7affe54e5950215e69df4afcc6f7f5dd7eeceb810afda0dd5e1d3R85) ## Which issue(s) this PR fixes Related to https://github.com/grafana/support-escalations/issues/8567 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- ...alerts_aler_channel_81aeec_idx_and_more.py | 21 +++++++++++++++++++ engine/apps/alerts/models/alert_group.py | 5 ++++- engine/apps/api/views/alert_group.py | 4 ++-- engine/common/api_helpers/paginators.py | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 engine/apps/alerts/migrations/0043_remove_alertgroup_alerts_aler_channel_81aeec_idx_and_more.py diff --git a/engine/apps/alerts/migrations/0043_remove_alertgroup_alerts_aler_channel_81aeec_idx_and_more.py b/engine/apps/alerts/migrations/0043_remove_alertgroup_alerts_aler_channel_81aeec_idx_and_more.py new file mode 100644 index 00000000..087d1322 --- /dev/null +++ b/engine/apps/alerts/migrations/0043_remove_alertgroup_alerts_aler_channel_81aeec_idx_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.7 on 2023-12-06 13:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('alerts', '0042_alertgroup_received_at'), + ] + + operations = [ + migrations.AddIndex( + model_name='alertgroup', + index=models.Index(fields=['channel_id', 'resolved', 'acknowledged', 'silenced', 'root_alert_group_id', 'started_at'], name='alert_group_list_index'), + ), + migrations.RemoveIndex( + model_name='alertgroup', + name='alerts_aler_channel_81aeec_idx', + ), + ] diff --git a/engine/apps/alerts/models/alert_group.py b/engine/apps/alerts/models/alert_group.py index cb1036d0..5a891a44 100644 --- a/engine/apps/alerts/models/alert_group.py +++ b/engine/apps/alerts/models/alert_group.py @@ -457,7 +457,10 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. "is_open_for_grouping", ] indexes = [ - models.Index(fields=["channel_id", "resolved", "acknowledged", "silenced", "root_alert_group_id"]), + models.Index( + fields=["channel_id", "resolved", "acknowledged", "silenced", "root_alert_group_id", "started_at"], + name="alert_group_list_index", + ), ] def __str__(self): diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 860c7092..230e43e2 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -30,7 +30,7 @@ from apps.user_management.models import Team, User from common.api_helpers.exceptions import BadRequest from common.api_helpers.filters import NO_TEAM_VALUE, DateRangeFilterMixin, ModelFieldFilterMixin from common.api_helpers.mixins import PreviewTemplateMixin, PublicPrimaryKeyMixin, TeamFilteringMixin -from common.api_helpers.paginators import TwentyFiveCursorPaginator +from common.api_helpers.paginators import AlertGroupCursorPaginator def get_integration_queryset(request): @@ -309,7 +309,7 @@ class AlertGroupView( serializer_class = AlertGroupSerializer - pagination_class = TwentyFiveCursorPaginator + pagination_class = AlertGroupCursorPaginator filter_backends = [SearchFilter, AlertGroupFilterBackend] # search_fields = ["=public_primary_key", "=inside_organization_number", "web_title_cache"] diff --git a/engine/common/api_helpers/paginators.py b/engine/common/api_helpers/paginators.py index 1e1a2028..554c3497 100644 --- a/engine/common/api_helpers/paginators.py +++ b/engine/common/api_helpers/paginators.py @@ -80,6 +80,6 @@ class FifteenPageSizePaginator(PathPrefixedPagePagination): page_size = 15 -class TwentyFiveCursorPaginator(PathPrefixedCursorPagination): +class AlertGroupCursorPaginator(PathPrefixedCursorPagination): page_size = 25 - ordering = "-started_at" + ordering = "-started_at" # ordering by "-started_at", so it uses the right index (see AlertGroup.Meta.indexes)