Skip to content

Commit 63ac060

Browse files
committed
cli: Reduce 'info' components API calls
We weren't being entirely optimal with our calls here. Rework things slightly to minimize the possible number of calls. Signed-off-by: Cole Robinson <[email protected]>
1 parent b26b066 commit 63ac060

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

bugzilla/_cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,18 +609,18 @@ def _filter_components(compdetails):
609609
return ret
610610

611611
productname = (opt.components or opt.component_owners or opt.versions)
612-
include_fields = ["name", "id"]
613612
fastcomponents = (opt.components and not opt.active_components)
613+
614+
include_fields = ["name", "id"]
615+
if opt.components or opt.component_owners:
616+
include_fields += ["components.name"]
617+
if opt.component_owners:
618+
include_fields += ["components.default_assigned_to"]
619+
if opt.active_components:
620+
include_fields += ["components.is_active"]
621+
614622
if opt.versions:
615623
include_fields += ["versions"]
616-
if opt.component_owners:
617-
include_fields += [
618-
"components.default_assigned_to",
619-
"components.name",
620-
]
621-
if (opt.active_components and
622-
any(["components" in i for i in include_fields])):
623-
include_fields += ["components.is_active"]
624624

625625
bz.refresh_products(names=productname and [productname] or None,
626626
include_fields=include_fields)

bugzilla/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,16 +838,15 @@ def getcomponents(self, product, force_refresh=False):
838838
proddict = self._lookup_product_in_cache(product)
839839
product_id = proddict.get("id", None)
840840

841-
if (force_refresh or
842-
product_id is None or
843-
product_id not in self._cache.component_names):
841+
if force_refresh or product_id is None:
844842
self.refresh_products(names=[product],
845843
include_fields=["name", "id"])
846844
proddict = self._lookup_product_in_cache(product)
847845
if "id" not in proddict:
848846
raise BugzillaError("Product '%s' not found" % product)
849847
product_id = proddict["id"]
850848

849+
if product_id not in self._cache.component_names:
851850
opts = {'product_id': product_id, 'field': 'component'}
852851
names = self._backend.bug_legal_values(opts)["values"]
853852
self._cache.component_names[product_id] = names

0 commit comments

Comments
 (0)