avoid using getLastHostUpdate

This commit is contained in:
Mike McLean 2023-04-07 20:35:31 -04:00 committed by Tomas Kopecek
parent 112730c77e
commit 9321ffebec
2 changed files with 46 additions and 24 deletions

View file

@ -3155,24 +3155,14 @@ def anon_handle_list_hosts(goptions, session, args):
else: else:
return 'N' return 'N'
try: if 'update_ts' not in hosts[0]:
first = session.getLastHostUpdate(hosts[0]['id'], ts=True) _get_host_update_oldhub(session, hosts)
opts = {'ts': True}
except koji.ParameterError:
# Hubs prior to v1.25.0 do not have a "ts" parameter for getLastHostUpdate
first = session.getLastHostUpdate(hosts[0]['id'])
opts = {}
# pull in the last update using multicall to speed it up a bit for host in hosts:
with session.multicall() as m: if host['update_ts'] is None:
result = [m.getLastHostUpdate(host['id'], **opts) for host in hosts[1:]]
updateList = [first] + [x.result for x in result]
for host, update in zip(hosts, updateList):
if update is None:
host['update'] = '-' host['update'] = '-'
else: else:
host['update'] = koji.formatTimeLong(update) host['update'] = koji.formatTimeLong(host['update_ts'])
host['enabled'] = yesno(host['enabled']) host['enabled'] = yesno(host['enabled'])
host['ready'] = yesno(host['ready']) host['ready'] = yesno(host['ready'])
host['arches'] = ','.join(host['arches'].split()) host['arches'] = ','.join(host['arches'].split())
@ -3222,6 +3212,33 @@ def anon_handle_list_hosts(goptions, session, args):
print(mask % host) print(mask % host)
def _get_host_update_oldhub(session, hosts):
"""Fetch host update times from older hubs"""
# figure out if hub supports ts parameter
try:
first = session.getLastHostUpdate(hosts[0]['id'], ts=True)
opts = {'ts': True}
except koji.ParameterError:
# Hubs prior to v1.25.0 do not have a "ts" parameter for getLastHostUpdate
first = session.getLastHostUpdate(hosts[0]['id'])
opts = {}
with session.multicall() as m:
result = [m.getLastHostUpdate(host['id'], **opts) for host in hosts[1:]]
updateList = [first] + [x.result for x in result]
for host, update in zip(hosts, updateList):
if 'ts' in opts:
host['update_ts'] = update
elif update is None:
host['update_ts'] = None
else:
dt = dateutil.parser.parse(update)
host['update_ts'] = time.mktime(dt.timetuple())
def anon_handle_list_pkgs(goptions, session, args): def anon_handle_list_pkgs(goptions, session, args):
"[info] Print the package listing for tag or for owner" "[info] Print the package listing for tag or for owner"
usage = "usage: %prog list-pkgs [options]" usage = "usage: %prog list-pkgs [options]"
@ -3662,11 +3679,10 @@ def anon_handle_hostinfo(goptions, session, args):
print("Comment:") print("Comment:")
print("Enabled: %s" % (info['enabled'] and 'yes' or 'no')) print("Enabled: %s" % (info['enabled'] and 'yes' or 'no'))
print("Ready: %s" % (info['ready'] and 'yes' or 'no')) print("Ready: %s" % (info['ready'] and 'yes' or 'no'))
try:
update = session.getLastHostUpdate(info['id'], ts=True) if 'update_ts' not in info:
except koji.ParameterError: _get_host_update_oldhub(session, [info])
# Hubs prior to v1.25.0 do not have a "ts" parameter for getLastHostUpdate update = info['update_ts']
update = session.getLastHostUpdate(info['id'])
if update is None: if update is None:
update = "never" update = "never"
else: else:

View file

@ -1713,11 +1713,17 @@ def hosts(environ, state='enabled', start=None, order='name', ready='all', chann
values['channels'] = server.listChannels() values['channels'] = server.listChannels()
with server.multicall() as m: if hosts and 'update_ts' not in hosts[0]:
updates = [m.getLastHostUpdate(host['id'], ts=True) for host in hosts] # be nice with older hub
# TODO remove this compat workaround after a release
with server.multicall() as m:
updates = [m.getLastHostUpdate(host['id'], ts=True) for host in hosts]
for host, lastUpdate in zip(hosts, updates): for host, lastUpdate in zip(hosts, updates):
host['last_update'] = lastUpdate.result host['last_update'] = lastUpdate.result
else:
for host in hosts:
host['last_update'] = koji.formatTimeLong(host['update_ts'])
# Paginate after retrieving last update info so we can sort on it # Paginate after retrieving last update info so we can sort on it
kojiweb.util.paginateList(values, hosts, start, 'hosts', 'host', order) kojiweb.util.paginateList(values, hosts, start, 'hosts', 'host', order)