mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Speed up /jobs for salt-api when run under cherrypy.
Currently, if a jid is supplied, two runners are run (both jobs.lookup_jid and jobs.list_job). This is unnecessary because the return from jobs.list_job contains all of the information from jobs.lookup_jid as well. This change runs only jobs.list_job in this case and builds an appropriate return from the output, netting an ~ 40% decrease in response time for this endpoint when a jid is supplied.
This commit is contained in:
parent
0638418d22
commit
4778bc7365
1 changed files with 4 additions and 12 deletions
|
@ -1319,29 +1319,21 @@ class Jobs(LowDataAdapter):
|
|||
'''
|
||||
lowstate = [{
|
||||
'client': 'runner',
|
||||
'fun': 'jobs.lookup_jid' if jid else 'jobs.list_jobs',
|
||||
'fun': 'jobs.list_job' if jid else 'jobs.list_jobs',
|
||||
'jid': jid,
|
||||
}]
|
||||
|
||||
if jid:
|
||||
lowstate.append({
|
||||
'client': 'runner',
|
||||
'fun': 'jobs.list_job',
|
||||
'jid': jid,
|
||||
})
|
||||
|
||||
cherrypy.request.lowstate = lowstate
|
||||
job_ret_info = list(self.exec_lowstate(
|
||||
token=cherrypy.session.get('token')))
|
||||
|
||||
ret = {}
|
||||
if jid:
|
||||
job_ret, job_info = job_ret_info
|
||||
ret['info'] = [job_info]
|
||||
ret['info'] = job_ret_info[0]
|
||||
ret['return'] = [dict((k, job_ret_info[0]['Result'][k]['return']) for k in job_ret_info[0]['Result'])]
|
||||
else:
|
||||
job_ret = job_ret_info[0]
|
||||
ret['return'] = job_ret_info[0]
|
||||
|
||||
ret['return'] = [job_ret]
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue