mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Remove unused functions for getting template statistics
This commit is contained in:
@@ -30,7 +30,6 @@ from app.models import (
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
ScheduledNotification,
|
||||
Template,
|
||||
KEY_TYPE_TEST,
|
||||
LETTER_TYPE,
|
||||
NOTIFICATION_CREATED,
|
||||
@@ -51,39 +50,6 @@ from app.utils import get_london_midnight_in_utc
|
||||
from app.utils import midnight_n_days_ago, escape_special_characters
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_template_usage(service_id, day):
|
||||
start = get_london_midnight_in_utc(day)
|
||||
end = get_london_midnight_in_utc(day + timedelta(days=1))
|
||||
|
||||
notifications_aggregate_query = db.session.query(
|
||||
func.count().label('count'),
|
||||
Notification.template_id
|
||||
).filter(
|
||||
Notification.created_at >= start,
|
||||
Notification.created_at < end,
|
||||
Notification.service_id == service_id,
|
||||
Notification.key_type != KEY_TYPE_TEST,
|
||||
).group_by(
|
||||
Notification.template_id
|
||||
).subquery()
|
||||
|
||||
query = db.session.query(
|
||||
Template.id,
|
||||
Template.name,
|
||||
Template.template_type,
|
||||
Template.is_precompiled_letter,
|
||||
func.coalesce(notifications_aggregate_query.c.count, 0).label('count')
|
||||
).outerjoin(
|
||||
notifications_aggregate_query,
|
||||
notifications_aggregate_query.c.template_id == Template.id
|
||||
).filter(
|
||||
Template.service_id == service_id
|
||||
).order_by(Template.name)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_last_template_usage(template_id, template_type, service_id):
|
||||
# By adding the service_id to the filter the performance of the query is greatly improved.
|
||||
|
||||
Reference in New Issue
Block a user