Bug 1304148 - Simplify the code in the job-log-url endpoint

Reduce the number of SQL queries from 3 to just 1
This commit is contained in:
William Lachance 2016-09-20 15:26:31 -04:00
Родитель 8fdf0f36d2
Коммит 3b3e55ab66
1 изменённых файлов: 4 добавлений и 6 удалений

Просмотреть файл

@ -31,8 +31,6 @@ class JobLogUrlViewSet(viewsets.ReadOnlyModelViewSet):
GET method implementation for list view
job_id -- Mandatory filter indicating which job these log belongs to.
"""
repository = Repository.objects.get(name=project)
job_id = request.query_params.get('job_id')
if not job_id:
raise ParseError(
@ -42,7 +40,7 @@ class JobLogUrlViewSet(viewsets.ReadOnlyModelViewSet):
except ValueError:
raise ParseError(detail="The job_id parameter must be an integer")
jobs = Job.objects.filter(repository=repository,
project_specific_id=job_id)
return Response([self._log_as_dict(log) for log in
JobLog.objects.filter(job__in=jobs)])
logs = JobLog.objects.filter(job__repository__name=project,
job__project_specific_id=job_id)
return Response([self._log_as_dict(log) for log in logs])