use service statistics endpoint instead of detailed service

we're not actually looking at the detailed service aspects - just
the stats. We're doing this in three places:

* dashboard
* notification activity page
* when checking jobs to see if we're over the daily limit

change these places to use a new api endpoint (service/id/statistics),
which hopefully be a little more performant, and will definitely be a
little more organised - moving away from generic endpoints with loads
of optional parameters.

We still need the detailed endpoints for the platform admin page tho.

Depends on https://github.com/alphagov/notifications-api/pull/1865
This commit is contained in:
Leo Hemsted
2018-05-09 13:53:02 +01:00
parent e47a459757
commit 78a6f86043
11 changed files with 93 additions and 136 deletions

View File

@@ -36,30 +36,13 @@ class ServiceAPIClient(NotifyAdminAPIClient):
@cache.set('service-{service_id}')
def get_service(self, service_id):
return self._get_service(service_id, detailed=False, today_only=False)
def get_detailed_service(self, service_id):
return self._get_service(service_id, detailed=True, today_only=False)
def get_detailed_service_for_today(self, service_id):
return self._get_service(service_id, detailed=True, today_only=True)
def _get_service(self, service_id, detailed, today_only):
"""
Retrieve a service.
:param detailed - return additional details, including notification statistics
:param today_only - return statistics only for today. No effect if detailed not passed in
"""
params = {}
if detailed:
params['detailed'] = detailed
if today_only:
params['today_only'] = today_only
return self.get('/service/{0}'.format(service_id))
return self.get(
'/service/{0}'.format(service_id),
params=params)
def get_service_statistics(self, service_id, today_only):
return self.get('/service/{0}/statistics'.format(service_id), params={'today_only': today_only})['data']
def get_services(self, params_dict=None):
"""