Skip to content

Commit

Permalink
Merge pull request #5067 from grafana/julia/add_started_at_default_fi…
Browse files Browse the repository at this point in the history
…lter_value

Add default value for `started_at` filter for `/alertgroups` internal endpoint
  • Loading branch information
Ferril authored Sep 24, 2024
2 parents f5f18f2 + 1065748 commit cd54600
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions engine/apps/api/views/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def get_queryset(self, ignore_filtering_by_available_teams=False):
alert_receive_channels_ids = list(alert_receive_channels_qs.values_list("id", flat=True))
queryset = AlertGroup.objects.filter(channel__in=alert_receive_channels_ids)

# This is a quick fix to speed up requests from mobile app by adding default `started_at` filter value
if not self.request.query_params.get("started_at"):
queryset = queryset.filter(started_at__gte=timezone.now() - timezone.timedelta(days=30))

if self.action in ("list", "stats") and settings.ALERT_GROUPS_DISABLE_PREFER_ORDERING_INDEX:
# workaround related to MySQL "ORDER BY LIMIT Query Optimizer Bug"
# read more: https://hackmysql.com/infamous-order-by-limit-query-optimizer-bug/
Expand Down

0 comments on commit cd54600

Please sign in to comment.