From 76d5f14952ab755854fa4b38e6320221c727eacd Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 4 Oct 2016 09:51:41 +0100 Subject: [PATCH] Filter unbillable notifications before calculating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/dao/notifications_dao.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index cebb1964d..037a0b7b4 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -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