split up _query_for_billing_data into three separate queries

the queries all return lots of columns, but each query has columns it
doesn't care about. eg emails don't have billable units or international
flag, letters don't have international flag, sms don't have a page count
etc. additionally, the query was grouping on things that never change,
like service id and notification type.

by making all of these literals (as in `select 1 as foo`) we see times
that are over 50% quicker for gov.uk email service.

Note: One of the tests changed because previously it involved emails and
sms with statuses that they could never be (eg returned-letter)
This commit is contained in:
Leo Hemsted
2020-02-19 10:58:06 +00:00
committed by Rebecca Law
parent f7f6be56c7
commit 0f6f2f1b91
4 changed files with 126 additions and 59 deletions

View File

@@ -166,6 +166,7 @@ def test_create_nightly_billing_for_day_different_templates(
multiplier = [0, 1]
billable_units = [0, 1]
rate = [0, Decimal(1.33)]
for i, record in enumerate(records):
assert record.bst_date == datetime.date(yesterday)
assert record.rate == rate[i]