summaryrefslogtreecommitdiff
path: root/zuul/web
diff options
context:
space:
mode:
authorMatthieu Huin <mhuin@redhat.com>2021-12-02 15:56:03 +0100
committerMatthieu Huin <mhuin@redhat.com>2021-12-02 21:59:48 +0100
commitbc211ea7982d630e385bfdd1e9cffbaa3c8f3338 (patch)
treefb4a143914890785b2e65b7c12005ecdb59c15f1 /zuul/web
parent31b2c944127c23c1507abf87a523117eb706a0d0 (diff)
downloadzuul-bc211ea7982d630e385bfdd1e9cffbaa3c8f3338.tar.gz
REST API: add idx_min, idx_max params to getBuilds, getBuildsets
Allow filtering searches per primary index; ie return only builds or buildsets whose primary index key is greater than idx_min or lower than idx_max. This is expected to increase queries speed compared to using the offset argument when it is possible to do so, since "offset" requires the database to sift through all results until the offset is reached. Change-Id: I420d71d7c62dad6d118310525e97b4a546f05f99
Diffstat (limited to 'zuul/web')
-rwxr-xr-xzuul/web/__init__.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py
index 46cd7561c..42457ded1 100755
--- a/zuul/web/__init__.py
+++ b/zuul/web/__init__.py
@@ -1237,6 +1237,7 @@ class ZuulWebAPI(object):
duration = None
ret = {
+ '_id': build.id,
'uuid': build.uuid,
'job_name': build.job_name,
'result': build.result,
@@ -1293,7 +1294,7 @@ class ZuulWebAPI(object):
branch=None, patchset=None, ref=None, newrev=None,
uuid=None, job_name=None, voting=None, nodeset=None,
result=None, final=None, held=None, complete=None,
- limit=50, skip=0):
+ limit=50, skip=0, idx_min=None, idx_max=None):
connection = self._get_connection()
if tenant not in self.zuulweb.abide.tenants.keys():
@@ -1306,12 +1307,18 @@ class ZuulWebAPI(object):
if complete is not None:
complete = complete.lower() == 'true'
+ try:
+ _idx_max = idx_max is not None and int(idx_max) or idx_max
+ _idx_min = idx_min is not None and int(idx_min) or idx_min
+ except ValueError:
+ raise cherrypy.HTTPError(400, 'idx_min, idx_max must be integers')
+
builds = connection.getBuilds(
tenant=tenant, project=project, pipeline=pipeline, change=change,
branch=branch, patchset=patchset, ref=ref, newrev=newrev,
uuid=uuid, job_name=job_name, voting=voting, nodeset=nodeset,
result=result, final=final, held=held, complete=complete,
- limit=limit, offset=skip)
+ limit=limit, offset=skip, idx_min=_idx_min, idx_max=_idx_max)
resp = cherrypy.response
resp.headers['Access-Control-Allow-Origin'] = '*'
@@ -1333,6 +1340,7 @@ class ZuulWebAPI(object):
def buildsetToDict(self, buildset, builds=[]):
ret = {
+ '_id': buildset.id,
'uuid': buildset.uuid,
'result': buildset.result,
'message': buildset.message,
@@ -1380,17 +1388,24 @@ class ZuulWebAPI(object):
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
def buildsets(self, tenant, project=None, pipeline=None, change=None,
branch=None, patchset=None, ref=None, newrev=None,
- uuid=None, result=None, complete=None, limit=50, skip=0):
+ uuid=None, result=None, complete=None, limit=50, skip=0,
+ idx_min=None, idx_max=None):
connection = self._get_connection()
if complete:
complete = complete.lower() == 'true'
+ try:
+ _idx_max = idx_max is not None and int(idx_max) or idx_max
+ _idx_min = idx_min is not None and int(idx_min) or idx_min
+ except ValueError:
+ raise cherrypy.HTTPError(400, 'idx_min, idx_max must be integers')
+
buildsets = connection.getBuildsets(
tenant=tenant, project=project, pipeline=pipeline, change=change,
branch=branch, patchset=patchset, ref=ref, newrev=newrev,
uuid=uuid, result=result, complete=complete,
- limit=limit, offset=skip)
+ limit=limit, offset=skip, idx_min=_idx_min, idx_max=_idx_max)
resp = cherrypy.response
resp.headers['Access-Control-Allow-Origin'] = '*'