From b0c5e1ec92e0251f526731d956ea3f515272e2b8 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Jun 25 2013 19:16:16 +0000 Subject: koji-gc: move sorting and filtering into the database --- diff --git a/hub/kojihub.py b/hub/kojihub.py index a5c1087..b415d3f 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5514,7 +5514,7 @@ def query_history(tables=None, **kwargs): return ret -def tag_history(build=None, tag=None, package=None, queryOpts=None): +def tag_history(build=None, tag=None, package=None, active=None, queryOpts=None): """Returns historical tag data package: only for given package @@ -5552,6 +5552,10 @@ def tag_history(build=None, tag=None, package=None, queryOpts=None): if package is not None: pkg_id = get_package_id(package, strict=True) clauses.append("package.id = %(pkg_id)i") + if active is True: + clauses.append("tag_listing.active is true") + elif active is False: + clauses.append("tag_listing.active is not true") query = QueryProcessor(columns=fields, aliases=aliases, tables=tables, joins=joins, clauses=clauses, values=locals(), opts=queryOpts) diff --git a/util/koji-gc b/util/koji-gc index 14881db..18788c6 100755 --- a/util/koji-gc +++ b/util/koji-gc @@ -792,11 +792,11 @@ def handle_prune(): if options.debug: pprint.pprint(policies.ruleset) #get tags - tags = [(t['name'], t) for t in session.listTags()] - tags.sort() + tags = session.listTags(queryOpts={'order': 'name'}) untagged = {} build_ids = {} - for tagname, taginfo in tags: + for taginfo in tags: + tagname = taginfo['name'] if tagname == options.trashcan_tag: if options.debug: print "Skipping trashcan tag: %s" % tagname @@ -821,16 +821,13 @@ def handle_prune(): if options.debug: print "Pruning tag: %s" % tagname #get builds - history = session.tagHistory(tag=tagname) + history = session.tagHistory(tag=tagname, active=True, queryOpts={'order': '-create_ts'}) if not history: if options.debug: print "No history for %s" % tagname continue - history = [(h['create_ts'], h) for h in history if h['active']] - history.sort() - history.reverse() #newest first pkghist = {} - for ts, h in history: + for h in history: pkghist.setdefault(h['name'], []).append(h) pkgs = pkghist.keys() pkgs.sort()