Optimise the query for getting the platform statistics for all services. The page should render for all time after this change.

This is one step closer to eliminating the need to read from NotificationHistory.
This commit is contained in:
Rebecca Law
2019-01-04 16:45:39 +00:00
parent 39963d9784
commit bd9a6352fd
4 changed files with 63 additions and 31 deletions

View File

@@ -289,6 +289,7 @@ def set_up_data():
create_notification(sms_template, created_at=datetime(2018, 10, 31, 11, 0, 0))
create_notification(sms_template, created_at=datetime(2018, 10, 31, 12, 0, 0), status='delivered')
create_notification(email_template, created_at=datetime(2018, 10, 31, 13, 0, 0), status='delivered')
return service_1, service_2
def test_fetch_notification_statuses_for_job(sample_template):
@@ -308,8 +309,32 @@ def test_fetch_notification_statuses_for_job(sample_template):
@freeze_time('2018-10-31 14:00')
def test_fetch_stats_for_all_services_by_date_range(notify_db_session):
set_up_data()
results = fetch_stats_for_all_services_by_date_range( start_date=date(2018, 10, 29),
end_date=date(2018, 10, 31))
print(results)
assert len(results) == 2
service_1, service_2 = set_up_data()
results = fetch_stats_for_all_services_by_date_range(start_date=date(2018, 10, 29),
end_date=date(2018, 10, 31))
assert len(results) == 5
assert results[0].service_id == service_1.id
assert results[0].notification_type == 'email'
assert results[0].status == 'delivered'
assert results[0].count == 4
assert results[1].service_id == service_1.id
assert results[1].notification_type == 'sms'
assert results[1].status == 'created'
assert results[1].count == 2
assert results[2].service_id == service_1.id
assert results[2].notification_type == 'sms'
assert results[2].status == 'delivered'
assert results[2].count == 11
assert results[3].service_id == service_2.id
assert results[3].notification_type == 'letter'
assert results[3].status == 'delivered'
assert results[3].count == 10
assert results[4].service_id == service_2.id
assert not results[4].notification_type
assert not results[4].status
assert not results[4].count