Create query to sum notificaitons for the message limit check, this is a bit more efficient.

Refactored send_notifications method so that it is more readible.
Refectored the test_send_notificaitons so that it uses parametrized test to avoid duplication.
This commit is contained in:
Rebecca Law
2016-10-03 10:57:10 +01:00
parent d27e1595d5
commit e3d418506a
5 changed files with 272 additions and 414 deletions
+14
View File
@@ -150,6 +150,20 @@ def dao_fetch_todays_stats_for_service(service_id):
).all()
def fetch_todays_total_message_count(service_id):
result = db.session.query(
func.count(Notification.id).label('count')
).filter(
Notification.service_id == service_id,
Notification.key_type != KEY_TYPE_TEST,
func.date(Notification.created_at) == date.today()
).group_by(
Notification.notification_type,
Notification.status,
).first()
return 0 if result is None else result.count
def _stats_for_service_query(service_id):
return db.session.query(
Notification.notification_type,