Remove unneeded filter making query slower (#3570)
There is no index for the `received_at` column, and the filter isn't really needed (aggregation will work in any case, considering only the entries for which we have data).
This commit is contained in:
parent
6c1ac8aa73
commit
6dada51133
2 changed files with 5 additions and 3 deletions
|
|
@ -106,7 +106,7 @@ def check_escalation_finished_task() -> None:
|
|||
)
|
||||
total_alert_groups_count = alert_groups.count()
|
||||
|
||||
creation_deltas = alert_groups.filter(received_at__isnull=False).aggregate(
|
||||
creation_deltas = alert_groups.aggregate(
|
||||
avg_delta=Avg(F("started_at") - F("received_at")),
|
||||
max_delta=Max(F("started_at") - F("received_at")),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ def make_alert_group_that_started_at_specific_date(make_alert_group):
|
|||
):
|
||||
# we can't simply pass started_at to the fixture because started_at is being "auto-set" on the Model
|
||||
alert_group = make_alert_group(alert_receive_channel, **kwargs)
|
||||
alert_group.received_at = started_at - timezone.timedelta(seconds=received_delta)
|
||||
if received_delta is not None:
|
||||
alert_group.received_at = started_at - timezone.timedelta(seconds=received_delta)
|
||||
alert_group.started_at = started_at
|
||||
alert_group.save()
|
||||
|
||||
|
|
@ -358,6 +359,7 @@ def test_check_escalation_finished_task_calls_audit_alert_group_escalation_for_e
|
|||
alert_group1 = make_alert_group_that_started_at_specific_date(alert_receive_channel, received_delta=1)
|
||||
alert_group2 = make_alert_group_that_started_at_specific_date(alert_receive_channel, received_delta=5)
|
||||
alert_group3 = make_alert_group_that_started_at_specific_date(alert_receive_channel, received_delta=12)
|
||||
alert_group3 = make_alert_group_that_started_at_specific_date(alert_receive_channel, received_delta=None)
|
||||
|
||||
def _mocked_audit_alert_group_escalation(alert_group):
|
||||
if not alert_group.id == alert_group3.id:
|
||||
|
|
@ -376,7 +378,7 @@ def test_check_escalation_finished_task_calls_audit_alert_group_escalation_for_e
|
|||
|
||||
assert "Alert group ingestion/creation avg delta seconds: 6" in caplog.text
|
||||
assert "Alert group ingestion/creation max delta seconds: 12" in caplog.text
|
||||
assert "Alert group notifications success ratio: 33.33" in caplog.text
|
||||
assert "Alert group notifications success ratio: 25.00" in caplog.text
|
||||
|
||||
mocked_audit_alert_group_escalation.assert_any_call(alert_group1)
|
||||
mocked_audit_alert_group_escalation.assert_any_call(alert_group2)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue