tests and optimizations for UJT list with non-joblet recent_jobs

This commit is contained in:
AlanCoding
2018-12-04 15:36:49 -05:00
parent 2a62e300a2
commit f09b8efa87
6 changed files with 52 additions and 40 deletions

View File

@@ -2983,13 +2983,16 @@ class JobTemplateMixin(object):
'''
def _recent_jobs(self, obj):
job_mgr = obj.unifiedjob_unified_jobs.non_polymorphic().exclude(job__job_slice_count__gt=1).only(
'id', 'status', 'finished', 'polymorphic_ctype_id')
type_mapping = {}
for model, ct in ContentType.objects.get_for_models(*UnifiedJob.__subclasses__()).iteritems():
type_mapping[ct.pk] = model._meta.verbose_name
return [{'id': x.id, 'status': x.status, 'finished': x.finished, 'type': type_mapping[x.polymorphic_ctype_id]}
for x in job_mgr.order_by('-created')[:10]]
# Exclude "joblets", jobs that ran as part of a sliced workflow job
uj_qs = obj.unifiedjob_unified_jobs.exclude(job__job_slice_count__gt=1).order_by('-created')
# Would like to apply an .only, but does not play well with non_polymorphic
# .only('id', 'status', 'finished', 'polymorphic_ctype_id')
optimized_qs = uj_qs.non_polymorphic()
return [{
'id': x.id, 'status': x.status, 'finished': x.finished,
# Make type consistent with API top-level key, for instance workflow_job
'type': x.get_real_instance_class()._meta.verbose_name.replace(' ', '_')
} for x in optimized_qs[:10]]
def get_summary_fields(self, obj):
d = super(JobTemplateMixin, self).get_summary_fields(obj)