Merge pull request #2178 from alphagov/cache-has-jobs

Check if any jobs exist before querying jobs
This commit is contained in:
Chris Hill-Scott
2018-07-31 11:17:42 +01:00
committed by GitHub
5 changed files with 126 additions and 27 deletions

View File

@@ -275,21 +275,18 @@ def aggregate_usage(template_statistics, sort_key='count'):
def get_dashboard_partials(service_id):
# all but scheduled and cancelled
statuses_to_display = job_api_client.JOB_STATUSES - {'scheduled', 'cancelled'}
template_statistics = aggregate_usage(
template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
)
scheduled_jobs = sorted(
job_api_client.get_jobs(service_id, statuses=['scheduled'])['data'],
key=lambda job: job['scheduled_for']
)
immediate_jobs = [
add_rate_to_job(job)
for job in job_api_client.get_jobs(service_id, limit_days=7, statuses=statuses_to_display)['data']
]
scheduled_jobs, immediate_jobs = [], []
if job_api_client.has_jobs(service_id):
scheduled_jobs = job_api_client.get_scheduled_jobs(service_id)
immediate_jobs = [
add_rate_to_job(job)
for job in job_api_client.get_immediate_jobs(service_id)
]
stats = service_api_client.get_service_statistics(service_id, today_only=False)
column_width, max_notifiction_count = get_column_properties(
number_of_columns=(

View File

@@ -42,9 +42,7 @@ from app.utils import (
@user_has_permissions('view_activity')
def view_jobs(service_id):
page = int(request.args.get('page', 1))
# all but scheduled and cancelled
statuses_to_display = job_api_client.JOB_STATUSES - {'scheduled', 'cancelled'}
jobs_response = job_api_client.get_jobs(service_id, statuses=statuses_to_display, page=page)
jobs_response = job_api_client.get_page_of_jobs(service_id, page=page)
jobs = [
add_rate_to_job(job) for job in jobs_response['data']
]