lazy opt for build_references
This commit is contained in:
parent
3c9d77f479
commit
be93ac1a3a
1 changed files with 26 additions and 5 deletions
|
|
@ -7073,12 +7073,17 @@ def build_map():
|
|||
WHERE built.state = %(st_complete)i AND used.state =%(st_complete)i"""
|
||||
return _multiRow(q, locals(), fields)
|
||||
|
||||
def build_references(build_id, limit=None):
|
||||
|
||||
def build_references(build_id, limit=None, lazy=False):
|
||||
"""Returns references to a build
|
||||
|
||||
This call is used to determine whether a build can be deleted
|
||||
The optional limit arg is used to limit the size of the buildroot
|
||||
references.
|
||||
|
||||
:param int build_id: numeric build id
|
||||
:param int limit: If given, only return up to N results of each ref type
|
||||
:param bool lazy: If true, stop when any reference is found
|
||||
|
||||
:returns: dict of reference results for each reference type
|
||||
"""
|
||||
|
||||
ret = {}
|
||||
|
|
@ -7088,6 +7093,9 @@ def build_references(build_id, limit=None):
|
|||
WHERE build_id = %(build_id)i AND active = TRUE"""
|
||||
ret['tags'] = _multiRow(q, locals(), ('id', 'name'))
|
||||
|
||||
if lazy and ret['tags']:
|
||||
return ret
|
||||
|
||||
#we'll need the component rpm and archive ids for the rest
|
||||
q = """SELECT id FROM rpminfo WHERE build_id=%(build_id)i"""
|
||||
build_rpm_ids = _fetchMulti(q, locals())
|
||||
|
|
@ -7113,6 +7121,9 @@ def build_references(build_id, limit=None):
|
|||
break
|
||||
ret['rpms'] = to_list(idx.values())
|
||||
|
||||
if lazy and ret['rpms']:
|
||||
return ret
|
||||
|
||||
ret['component_of'] = []
|
||||
# find images/archives that contain the build rpms
|
||||
fields = ['archive_id']
|
||||
|
|
@ -7125,6 +7136,9 @@ def build_references(build_id, limit=None):
|
|||
archive_ids = [i[0] for i in query.execute()]
|
||||
ret['component_of'].extend(archive_ids)
|
||||
|
||||
if lazy and ret['component_of']:
|
||||
return ret
|
||||
|
||||
# find archives whose buildroots we were in
|
||||
fields = ('id', 'type_id', 'type_name', 'build_id', 'filename')
|
||||
idx = {}
|
||||
|
|
@ -7144,6 +7158,9 @@ def build_references(build_id, limit=None):
|
|||
break
|
||||
ret['archives'] = to_list(idx.values())
|
||||
|
||||
if lazy and ret['archives']:
|
||||
return ret
|
||||
|
||||
# find images/archives that contain the build archives
|
||||
fields = ['archive_id']
|
||||
clauses = ['archive_components.component_id = %(archive_id)s']
|
||||
|
|
@ -7155,6 +7172,9 @@ def build_references(build_id, limit=None):
|
|||
archive_ids = [i[0] for i in query.execute()]
|
||||
ret['component_of'].extend(archive_ids)
|
||||
|
||||
if lazy and ret['component_of']:
|
||||
return ret
|
||||
|
||||
# find timestamp of most recent use in a buildroot
|
||||
query = QueryProcessor(
|
||||
columns=['standard_buildroot.create_event'],
|
||||
|
|
@ -7198,6 +7218,7 @@ def build_references(build_id, limit=None):
|
|||
|
||||
return ret
|
||||
|
||||
|
||||
def delete_build(build, strict=True, min_ref_age=604800):
|
||||
"""delete a build, if possible
|
||||
|
||||
|
|
@ -9280,8 +9301,8 @@ class RootExports(object):
|
|||
|
||||
buildMap = staticmethod(build_map)
|
||||
deleteBuild = staticmethod(delete_build)
|
||||
def buildReferences(self, build, limit=None):
|
||||
return build_references(get_build(build, strict=True)['id'], limit)
|
||||
def buildReferences(self, build, limit=None, lazy=False):
|
||||
return build_references(get_build(build, strict=True)['id'], limit, lazy)
|
||||
|
||||
addVolume = staticmethod(add_volume)
|
||||
removeVolume = staticmethod(remove_volume)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue