mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 22:16:00 -03:30
WFJT activity stream optimization
This commit is contained in:
@@ -83,6 +83,8 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'network_credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'net'),
|
'network_credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'net'),
|
||||||
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed'),
|
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed'),
|
||||||
'job_template': DEFAULT_SUMMARY_FIELDS,
|
'job_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
|
'workflow_job_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
|
'workflow_job': DEFAULT_SUMMARY_FIELDS,
|
||||||
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
||||||
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('unified_job_type',),
|
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('unified_job_type',),
|
||||||
'last_job': DEFAULT_SUMMARY_FIELDS + ('finished', 'status', 'failed', 'license_error'),
|
'last_job': DEFAULT_SUMMARY_FIELDS + ('finished', 'status', 'failed', 'license_error'),
|
||||||
@@ -2999,13 +3001,17 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
rel = {}
|
rel = {}
|
||||||
if obj.actor is not None:
|
if obj.actor is not None:
|
||||||
rel['actor'] = reverse('api:user_detail', args=(obj.actor.pk,))
|
rel['actor'] = reverse('api:user_detail', args=(obj.actor.pk,))
|
||||||
for fk, __ in SUMMARIZABLE_FK_FIELDS.items() + [('workflow_job_template', 0)]:
|
for fk, __ in SUMMARIZABLE_FK_FIELDS.items():
|
||||||
if not hasattr(obj, fk):
|
if not hasattr(obj, fk):
|
||||||
continue
|
continue
|
||||||
allm2m = getattr(obj, fk).all()
|
allm2m = getattr(obj, fk).all()
|
||||||
if getattr(obj, fk).exists():
|
if getattr(obj, fk).exists():
|
||||||
rel[fk] = []
|
rel[fk] = []
|
||||||
|
id_list = []
|
||||||
for thisItem in allm2m:
|
for thisItem in allm2m:
|
||||||
|
if getattr(thisItem, 'id', None) in id_list:
|
||||||
|
continue
|
||||||
|
id_list.append(getattr(thisItem, 'id', None))
|
||||||
if fk == 'custom_inventory_script':
|
if fk == 'custom_inventory_script':
|
||||||
rel[fk].append(reverse('api:inventory_script_detail', args=(thisItem.id,)))
|
rel[fk].append(reverse('api:inventory_script_detail', args=(thisItem.id,)))
|
||||||
else:
|
else:
|
||||||
@@ -3017,7 +3023,7 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def get_summary_fields(self, obj):
|
def get_summary_fields(self, obj):
|
||||||
summary_fields = OrderedDict()
|
summary_fields = OrderedDict()
|
||||||
for fk, related_fields in SUMMARIZABLE_FK_FIELDS.items() + [('workflow_job_template', DEFAULT_SUMMARY_FIELDS)]:
|
for fk, related_fields in SUMMARIZABLE_FK_FIELDS.items():
|
||||||
try:
|
try:
|
||||||
if not hasattr(obj, fk):
|
if not hasattr(obj, fk):
|
||||||
continue
|
continue
|
||||||
@@ -3050,6 +3056,9 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
thisItemDict[field] = fval
|
thisItemDict[field] = fval
|
||||||
if fk == 'group':
|
if fk == 'group':
|
||||||
thisItemDict['inventory_id'] = getattr(thisItem, 'inventory_id', None)
|
thisItemDict['inventory_id'] = getattr(thisItem, 'inventory_id', None)
|
||||||
|
if thisItemDict.get('id', None):
|
||||||
|
if thisItemDict.get('id', None) in [obj_dict.get('id', None) for obj_dict in summary_fields[fk]]:
|
||||||
|
continue
|
||||||
summary_fields[fk].append(thisItemDict)
|
summary_fields[fk].append(thisItemDict)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -3087,6 +3087,13 @@ class WorkflowJobTemplateActivityStreamList(WorkflowsEnforcementMixin, ActivityS
|
|||||||
relationship = 'activitystream_set'
|
relationship = 'activitystream_set'
|
||||||
new_in_310 = True
|
new_in_310 = True
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
parent = self.get_parent_object()
|
||||||
|
self.check_parent_access(parent)
|
||||||
|
qs = self.request.user.get_queryset(self.model)
|
||||||
|
return qs.filter(Q(workflow_job_template=parent) |
|
||||||
|
Q(workflow_job_template_node__workflow_job_template=parent))
|
||||||
|
|
||||||
|
|
||||||
class WorkflowJobList(WorkflowsEnforcementMixin, ListCreateAPIView):
|
class WorkflowJobList(WorkflowsEnforcementMixin, ListCreateAPIView):
|
||||||
|
|
||||||
|
|||||||
@@ -2104,10 +2104,10 @@ class ActivityStreamAccess(BaseAccess):
|
|||||||
qs = self.model.objects.all()
|
qs = self.model.objects.all()
|
||||||
qs = qs.prefetch_related('organization', 'user', 'inventory', 'host', 'group', 'inventory_source',
|
qs = qs.prefetch_related('organization', 'user', 'inventory', 'host', 'group', 'inventory_source',
|
||||||
'inventory_update', 'credential', 'team', 'project', 'project_update',
|
'inventory_update', 'credential', 'team', 'project', 'project_update',
|
||||||
'permission', 'job_template', 'job', 'ad_hoc_command',
|
'job_template', 'job', 'ad_hoc_command',
|
||||||
'notification_template', 'notification', 'label', 'role', 'actor',
|
'notification_template', 'notification', 'label', 'role', 'actor',
|
||||||
'schedule', 'role', 'custom_inventory_script', 'unified_job_template',
|
'schedule', 'custom_inventory_script', 'unified_job_template',
|
||||||
'workflow_job_template')
|
'workflow_job_template', 'workflow_job')
|
||||||
if self.user.is_superuser or self.user.is_system_auditor:
|
if self.user.is_superuser or self.user.is_system_auditor:
|
||||||
return qs.all()
|
return qs.all()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user