Skip to content

Commit

Permalink
update filtering by started_at
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferril committed Sep 24, 2024
1 parent f577073 commit 1065748
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions engine/apps/api/views/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,6 @@ def get_serializer_class(self):

return super().get_serializer_class()

def _add_default_filter_started_at(self, queryset):
DEFAULT_STARTED_AT_TIMERANGE_DAYS = 30
end_time = timezone.now()
start_time = end_time - timedelta(days=DEFAULT_STARTED_AT_TIMERANGE_DAYS)
return queryset.filter(started_at__gte=start_time, started_at__lte=end_time)

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.

Expand All @@ -340,7 +334,7 @@ def get_queryset(self, ignore_filtering_by_available_teams=False):

# 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 = self._add_default_filter_started_at(queryset)
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"
Expand Down

0 comments on commit 1065748

Please sign in to comment.