From dcbdf8cefa235328e571ccc94db0307bca98ca19 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jan 23 2020 12:48:24 +0000 Subject: don't user full listTags in list-groups call Fixes: https://pagure.io/koji/issue/1954 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 3b398b5..1c0198e 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2584,23 +2584,33 @@ def anon_handle_list_groups(goptions, session, args): opts['event'] = event['id'] event['timestr'] = time.asctime(time.localtime(event['ts'])) print("Querying at event %(id)i (%(timestr)s)" % event) - tags = dict([(x['id'], x['name']) for x in session.listTags()]) tmp_list = [(x['name'], x) for x in session.getTagGroups(args[0], **opts)] tmp_list.sort() groups = [x[1] for x in tmp_list] + + tags_cache = {} + def get_cached_tag(tag_id): + if tag_id not in tags_cache: + tag = session.getTag(tag_id, strict=False) + if tag is None: + tags_cache[tag_id] = tag_id + else: + tags_cache[tag_id] = tag['name'] + return tags_cache[tag_id] + for group in groups: if len(args) > 1 and group['name'] != args[1]: continue - print("%s [%s]" % (group['name'], tags.get(group['tag_id'], group['tag_id']))) + print("%s [%s]" % (group['name'], get_cached_tag(group['tag_id']))) groups = [(x['name'], x) for x in group['grouplist']] groups.sort() for x in [x[1] for x in groups]: - x['tag_name'] = tags.get(x['tag_id'], x['tag_id']) + x['tag_name'] = get_cached_tag(x['tag_id']) print_group_list_req_group(x) pkgs = [(x['package'], x) for x in group['packagelist']] pkgs.sort() for x in [x[1] for x in pkgs]: - x['tag_name'] = tags.get(x['tag_id'], x['tag_id']) + x['tag_name'] = get_cached_tag(x['tag_id']) print_group_list_req_package(x) diff --git a/tests/test_cli/test_list_groups.py b/tests/test_cli/test_list_groups.py index 57cc9f0..4c689ed 100644 --- a/tests/test_cli/test_list_groups.py +++ b/tests/test_cli/test_list_groups.py @@ -172,7 +172,14 @@ class TestListGroups(utils.CliTestCase): pkg['tag_name'] = tags.get(pkg['tag_id'], pkg['tag_id']) expected += " %(package)s: %(basearchonly)s, %(type)s [%(tag_name)s]" % pkg + "\n" - self.session.listTags.return_value = _list_tags + #self.session.listTags.return_value = _list_tags + def get_tag(tag_id, strict=False): + self.assertFalse(strict) + for tag in _list_tags: + if tag['id'] == tag_id: + return tag + return None + self.session.getTag.side_effect = get_tag self.session.getTagGroups.return_value = _get_tag_groups args = ['fedora26-build'] args += [query_group] if query_group != '' else []