Filter unbillable notifications before calculating

Notifications with a `billable_units` count of `0` wont have any effect
on the result, but including them in the query will slow down the
grouping and summing of the results because it’ll have to loop over more
rows.
This commit is contained in:
Chris Hill-Scott
2016-10-04 09:51:41 +01:00
parent 7abe40b506
commit 76d5f14952

View File

@@ -221,6 +221,7 @@ def get_notification_billable_unit_count_per_month(service_id, year):
).order_by(
NotificationHistory.created_at
).filter(
NotificationHistory.billable_units != 0,
NotificationHistory.service_id == service_id,
NotificationHistory.created_at >= start,
NotificationHistory.created_at < end