use ft_notification_status and notifications for job statistics

we previously always read from NotificationHistory to get the
notification status stats for a job. Now, if the job is more than three
days old read from ft_notification_status table, otherwise read from
the notifications table (to keep live updates).
This commit is contained in:
Leo Hemsted
2018-12-12 12:57:33 +00:00
parent e555a7595b
commit b80beab76c
6 changed files with 120 additions and 20 deletions

View File

@@ -186,3 +186,14 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date):
else:
query = stats
return query.all()
def fetch_notification_statuses_for_job(job_id):
return db.session.query(
FactNotificationStatus.notification_status.label('status'),
func.sum(FactNotificationStatus.notification_count).label('count'),
).filter(
FactNotificationStatus.job_id == job_id,
).group_by(
FactNotificationStatus.notification_status
).all()

View File

@@ -16,7 +16,7 @@ from app.models import (
JOB_STATUS_PENDING,
JOB_STATUS_SCHEDULED,
LETTER_TYPE,
NotificationHistory,
Notification,
Template,
ServiceDataRetention
)
@@ -25,19 +25,14 @@ from app.variables import LETTER_TEST_API_FILENAME
@statsd(namespace="dao")
def dao_get_notification_outcomes_for_job(service_id, job_id):
query = db.session.query(
func.count(NotificationHistory.status).label('count'),
NotificationHistory.status
)
return query.filter(
NotificationHistory.service_id == service_id
return db.session.query(
func.count(Notification.status).label('count'),
Notification.status
).filter(
NotificationHistory.job_id == job_id
Notification.service_id == service_id,
Notification.job_id == job_id
).group_by(
NotificationHistory.status
).order_by(
asc(NotificationHistory.status)
Notification.status
).all()