create new stats endpoint

the admin app currently calls get_detailed_service, which gets
notification stats, adds them on to the rest of the detailed service
endpoint, and returns them. However, the admin app then only looks at
the stats - it doesn't look at the rest of the service object.

This is called in a few high profile places - the dashboard, the
notification summary page, and when you send a job. By creating a
separate endpoint that ignores the rest of the service object (and no
marshmallow too!), the hope is that we'll improve some slowness we've
been seeing.

Note: The old detailed function will still need to stay - it's used
by get_services(detailed=True) for the platform admin page.
This commit is contained in:
Leo Hemsted
2018-05-09 11:36:42 +01:00
parent 54d0e64582
commit c30f13ea67
2 changed files with 45 additions and 4 deletions

View File

@@ -170,6 +170,11 @@ def get_service_by_id(service_id):
return jsonify(data=data)
@service_blueprint.route('/<uuid:service_id>/statistics')
def get_service_notification_statistics(service_id):
return jsonify(data=get_service_statistics(service_id, request.args.get('today_only') == 'True'))
@service_blueprint.route('', methods=['POST'])
def create_service():
data = request.get_json()
@@ -411,12 +416,16 @@ def get_monthly_notification_stats(service_id):
def get_detailed_service(service_id, today_only=False):
service = dao_fetch_service_by_id(service_id)
service.statistics = get_service_statistics(service_id, today_only)
return detailed_service_schema.dump(service).data
def get_service_statistics(service_id, today_only):
# today_only flag is used by the send page to work out if the service will exceed their daily usage by sending a job
stats_fn = dao_fetch_todays_stats_for_service if today_only else dao_fetch_stats_for_service
stats = stats_fn(service_id)
service.statistics = statistics.format_statistics(stats)
return detailed_service_schema.dump(service).data
return statistics.format_statistics(stats)
def get_detailed_services(start_date, end_date, only_active=False, include_from_test_key=True):