From 3c0fc0b4b1fd1efb09e5e94f2e3844f90361ee0c Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Fri, 2 Dec 2022 17:16:49 -0500 Subject: [PATCH] koji-gc: use history to query trashcan contents as a side effect, we get the hub to apply our grace period for us --- util/koji-gc | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/util/koji-gc b/util/koji-gc index 9ff8a5c4..684788d0 100755 --- a/util/koji-gc +++ b/util/koji-gc @@ -664,11 +664,19 @@ def handle_delete(just_salvage=False): """ print("Getting list of builds in trash...") trashcan_tag = options.trashcan_tag - trash = sorted([(b['nvr'], b) for b in session.listTagged(trashcan_tag)]) - print("...got %i builds" % len(trash)) - # XXX - it would be better if there were more appropriate server calls for this grace_period = options.grace_period - import time + # using history makes for a smaller query that listTagged + history = session.queryHistory(tables=['tag_listing'], + tag=trashcan_tag, + active=True, + before=time.time()-grace_period) + # simulate needed binfo fields + binfos = history['tag_listing'] + for binfo in binfos: + binfo['nvr'] = '%(name)s-%(version)s-%(release)s' % binfo + binfo['id'] = binfo['build_id'] + trash = sorted([(b['nvr'], b) for b in binfos]) + print("...got %i builds" % len(trash)) print("1st pass: blacklist") continuing = [] @@ -709,30 +717,7 @@ def handle_delete(just_salvage=False): continue continuing.append((nvr, binfo)) - print("4th pass: history") - continuing, trash = [], continuing - for nvr, binfo in trash: - # determine how long this build has been in the trashcan - mcall.queryHistory(build=binfo['id'], tag=trashcan_tag) - - for (nvr, binfo), [history] in zip(trash, mcall.call_all()): - current = [x for x in history['tag_listing'] if x['active']] - if not current: - # untagged just now? - print("Warning: history missing for %s" % nvr) - pprint.pprint(binfo) - pprint.pprint(history) - continue - assert len(current) == 1 # see db constraint - current = current[0] - age = time.time() - current['create_ts'] - if age < grace_period: - if options.debug: - print("Skipping build %s, age=%i" % (nvr, age)) - continue - continuing.append(binfo) - - print("5th pass: deletion") + print("4th pass: deletion") for binfo in continuing: # go ahead and delete if options.test: