mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 22:42:28 -05:00
refactor dao_get_template_usage now that limit_days no longer used
doesnt need to have any conditional stuff now - always requires a date
This commit is contained in:
@@ -50,28 +50,18 @@ from app.utils import convert_utc_to_bst, get_london_midnight_in_utc
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_template_usage(service_id, *, limit_days=None, day=None):
|
||||
if bool(limit_days) == bool(day):
|
||||
raise ValueError('Must filter on either limit_days or a specific day')
|
||||
|
||||
query_filter = []
|
||||
|
||||
if limit_days:
|
||||
query_filter.append(Notification.created_at >= days_ago(limit_days))
|
||||
else:
|
||||
start = get_london_midnight_in_utc(day)
|
||||
end = get_london_midnight_in_utc(day + timedelta(days=1))
|
||||
query_filter.append(Notification.created_at >= start)
|
||||
query_filter.append(Notification.created_at < end)
|
||||
|
||||
query_filter.append(Notification.service_id == service_id)
|
||||
query_filter.append(Notification.key_type != KEY_TYPE_TEST)
|
||||
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(
|
||||
*query_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()
|
||||
|
||||
@@ -62,7 +62,6 @@ def get_template_statistics_for_last_n_days(service_id, limit_days):
|
||||
template_stats_by_id = Counter()
|
||||
|
||||
for day in last_n_days(limit_days):
|
||||
print('\n')
|
||||
# "{SERVICE_ID}-template-usage-{YYYY-MM-DD}"
|
||||
key = cache_key_for_service_template_usage_per_day(service_id, day)
|
||||
stats = redis_store.get_all_from_hash(key)
|
||||
|
||||
Reference in New Issue
Block a user