refactor template stats endpoint to read from new redis keys

New redis keys are partitioned per service per day. New process is as
follows:

* require a count of days to filter by. Currently admin always gives 7.
* for each day, check and see if there's anything in redis. There won't
  be if either a) redis is/was down or b) the service didn't send any
  notifications that day
  - if there isn't, go to the database and get a count out.
* combine all these stats together
* get the names/template types etc out of the DB at the end.
This commit is contained in:
Leo Hemsted
2018-04-12 10:46:22 +01:00
parent 5e702449cb
commit 9e8b6fd00d
7 changed files with 177 additions and 382 deletions

View File

@@ -50,7 +50,7 @@ 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):
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')
@@ -75,8 +75,9 @@ def dao_get_template_usage(service_id, limit_days=None, day=None):
).group_by(
Notification.template_id
).subquery()
query = db.session.query(
Template.id.label('template_id'),
Template.id,
Template.name,
Template.template_type,
Template.is_precompiled_letter,