Send '0', not 'null', to perf platform if no notifications are sent

This commit is contained in:
Katie Smith
2017-08-30 16:02:30 +01:00
parent a1a5fdedb1
commit 49a6bfc06b
2 changed files with 10 additions and 3 deletions

View File

@@ -527,7 +527,7 @@ def dao_get_total_notifications_sent_per_day_for_perfomance_platform(start_date,
"""
SELECT
count(notifications),
sum(CASE WHEN sent_at - created_at <= interval '10 seconds' THEN 1 ELSE 0 END)
coalesce(sum(CASE WHEN sent_at - created_at <= interval '10 seconds' THEN 1 ELSE 0 END), 0)
FROM notifications
WHERE
created_at > 'START DATE' AND
@@ -537,14 +537,14 @@ def dao_get_total_notifications_sent_per_day_for_perfomance_platform(start_date,
notification_type != 'letter';
"""
under_10_secs = Notification.sent_at - Notification.created_at <= timedelta(seconds=10)
sum_column = functions.sum(
sum_column = functions.coalesce(functions.sum(
case(
[
(under_10_secs, 1)
],
else_=0
)
)
), 0)
return db.session.query(
func.count(Notification.id).label('messages_total'),
sum_column.label('messages_within_10_secs')