Skip to content

Commit 79b0ec6

Browse files
committed
cli: Make info a bit more efficient
Figure out the products data we use upfront so we only need to make one Product.get call. Also make it more clear in the code that things are mutually exclusive.
1 parent 447202e commit 79b0ec6

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

bugzilla/_cli.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -581,44 +581,38 @@ def _do_info(bz, opt):
581581
"""
582582
# All these commands call getproducts internally, so do it up front
583583
# with minimal include_fields for speed
584+
productname = (opt.components or opt.component_owners or opt.versions)
584585
include_fields = ["name", "id"]
585586
if opt.versions:
586587
include_fields.append("versions")
587-
products = bz.getproducts(include_fields=include_fields)
588+
if opt.component_owners:
589+
include_fields += [
590+
"components.default_assigned_to",
591+
"components.name",
592+
]
593+
594+
bz.refresh_products(names=productname and [productname] or None,
595+
include_fields=include_fields)
588596

589597
if opt.products:
590-
for name in sorted([p["name"] for p in products]):
598+
for name in sorted([p["name"] for p in bz.getproducts()]):
591599
print(name)
592600

593-
if opt.components:
594-
for name in sorted(bz.getcomponents(opt.components)):
601+
elif opt.components:
602+
for name in sorted(bz.getcomponents(productname)):
595603
print(name)
596604

597-
if opt.component_owners:
598-
# Looking up this info for rhbz 'Fedora' product is sloooow
599-
# since there are so many components. So delay getting this
600-
# info until as late as possible
601-
bz.refresh_products(names=[opt.component_owners],
602-
include_fields=include_fields + [
603-
"components.default_assigned_to",
604-
"components.default_qa_contact",
605-
"components.name",
606-
"components.description"])
607-
608-
component_details = bz.getcomponentsdetails(opt.component_owners)
605+
elif opt.versions:
606+
proddict = bz.getproducts()[0]
607+
for v in proddict['versions']:
608+
print(to_encoding(v["name"]))
609+
610+
elif opt.component_owners:
611+
component_details = bz.getcomponentsdetails(productname)
609612
for c in sorted(component_details):
610613
print(to_encoding(u"%s: %s" % (c,
611614
component_details[c]['default_assigned_to'])))
612615

613-
if opt.versions:
614-
for p in products:
615-
if p['name'] != opt.versions:
616-
continue
617-
if "versions" in p:
618-
for v in p['versions']:
619-
print(to_encoding(v["name"]))
620-
break
621-
622616

623617
def _convert_to_outputformat(output):
624618
fmt = ""

0 commit comments

Comments
 (0)