1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

prefetch UnifiedJob related credentials

This commit is contained in:
AlanCoding 2017-11-15 22:32:29 -05:00
parent d6b10b7f44
commit 8cb5ce8307
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
2 changed files with 6 additions and 3 deletions

View File

@ -1939,6 +1939,7 @@ class UnifiedJobTemplateAccess(BaseAccess):
prefetch_related = (
'last_job',
'current_job',
'credentials__credential_type',
Prefetch('labels', queryset=Label.objects.all().order_by('name')),
)
@ -1982,6 +1983,7 @@ class UnifiedJobAccess(BaseAccess):
'unified_job_node__workflow_job',
'unified_job_template',
'instance_group',
'credentials__credential_type',
Prefetch('labels', queryset=Label.objects.all().order_by('name')),
)

View File

@ -185,9 +185,10 @@ class JobOptions(BaseModel):
return cred.pk
def get_deprecated_credential(self, kind):
try:
return self.credentials.filter(credential_type__kind=kind).first()
except IndexError:
for cred in self.credentials.all():
if cred.credential_type.kind == kind:
return cred
else:
return None
# TODO: remove when API v1 is removed