Skip to content

Commit f5079ac

Browse files
committed
Bugzilla: Drop use of legal_values in getcomponents
It's deprecated and will be removed eventually, and product_get isn't too much slower these days Remove traces of legal_values, as it's no longer used Signed-off-by: Cole Robinson <crobinso@redhat.com>
1 parent 89b57cf commit f5079ac

10 files changed

Lines changed: 23 additions & 43 deletions

bugzilla/_backendbase.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ def bug_history(self, bug_ids, paramdict):
123123
"""
124124
raise NotImplementedError()
125125

126-
def bug_legal_values(self, paramdict):
127-
"""
128-
Old style fields querying
129-
http://bugzilla.readthedocs.io/en/latest/api/core/v1/field.html#legal-values
130-
"""
131-
raise NotImplementedError()
132-
133126
def bug_search(self, paramdict):
134127
"""
135128
Search/query bugs

bugzilla/_backendxmlrpc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def bug_history(self, bug_ids, paramdict):
195195
data = paramdict.copy()
196196
data["ids"] = listify(bug_ids)
197197
return self._xmlrpc_proxy.Bug.history(data)
198-
def bug_legal_values(self, paramdict):
199-
return self._xmlrpc_proxy.Bug.legal_values(paramdict)
200198
def bug_search(self, paramdict):
201199
return self._xmlrpc_proxy.Bug.search(paramdict)
202200
def bug_update(self, bug_ids, paramdict):

bugzilla/base.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,6 @@ def getcomponents(self, product, force_refresh=False):
870870
"""
871871
Return a list of component names for the passed product.
872872
873-
This can be implemented with Product.get, but behind the
874-
scenes it uses Bug.legal_values. Reason being that on bugzilla
875-
instances with tons of components, like bugzilla.redhat.com
876-
Product=Fedora for example, there's a 10x speed difference
877-
even with properly limited Product.get calls.
878-
879873
On first invocation the value is cached, and subsequent calls
880874
will return the cached data.
881875
@@ -885,17 +879,22 @@ def getcomponents(self, product, force_refresh=False):
885879
proddict = self._lookup_product_in_cache(product)
886880
product_id = proddict.get("id", None)
887881

888-
if force_refresh or product_id is None:
889-
self.refresh_products(names=[product],
890-
include_fields=["name", "id"])
882+
if (force_refresh or product_id is None or
883+
"components" not in proddict):
884+
self.refresh_products(
885+
names=[product],
886+
include_fields=["name", "id", "components.name"])
891887
proddict = self._lookup_product_in_cache(product)
892888
if "id" not in proddict:
893889
raise BugzillaError("Product '%s' not found" % product)
894890
product_id = proddict["id"]
895891

896892
if product_id not in self._cache.component_names:
897-
opts = {'product_id': product_id, 'field': 'component'}
898-
names = self._backend.bug_legal_values(opts)["values"]
893+
names = []
894+
for comp in proddict.get("components", []):
895+
name = comp.get("name")
896+
if name:
897+
names.append(name)
899898
self._cache.component_names[product_id] = names
900899

901900
return self._cache.component_names[product_id]
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
comp1
2-
hey-imma-comp
3-
test-comp-2
1+
backend/kernel
2+
client-interfaces
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{'include_fields': ['name', 'id'], 'names': ['test-fake-product']}
1+
{'include_fields': ['name', 'id', 'components.name'],
2+
'names': ['test-fake-product']}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{'include_fields': ['name', 'id'], 'names': [0]}
1+
{'include_fields': ['name', 'id', 'components.name'], 'names': [0]}

tests/data/mockargs/test_info_components-legalvalues.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/mockbackend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ def bug_comments(self, *args):
6666
return self.__helper(args)
6767
def bug_create(self, *args):
6868
return self.__helper(args)
69-
def bug_legal_values(self, *args):
70-
return self.__helper(args)
7169
def bug_history(self, *args):
7270
return self.__helper(args)
7371
def bug_get(self, *args):

tests/test_api_products.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def test_api_products():
5050
]}
5151

5252
compnames = ["client-interfaces", "configuration"]
53-
legal_values = {'values': compnames}
54-
5553
fakebz = tests.mockbackend.make_bz(
5654
product_get_enterable_args=None,
5755
product_get_enterable_return=prod_list_return,
@@ -75,8 +73,6 @@ def test_api_products():
7573
fakebz = tests.mockbackend.make_bz(
7674
product_get_args="data/mockargs/test_api_products_get2.txt",
7775
product_get_return=prod_get_return,
78-
bug_legal_values_args=None,
79-
bug_legal_values_return=legal_values,
8076
)
8177

8278
# Lookup in product cache by name

tests/test_cli_info.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,22 @@ def test_info(run_cli):
4747
tests.utils.diff_compare(out, cliprefix + "versions.txt")
4848

4949
# info --components
50-
legal_values = {'values': ["comp1", "test-comp-2", "hey-imma-comp"]}
50+
prod_get_comp_active = {'products': [
51+
{'id': 7, 'name': 'test-fake-product',
52+
'components': [
53+
{'is_active': True, 'name': 'backend/kernel'},
54+
{'is_active': True, 'name': 'client-interfaces'},
55+
]},
56+
]}
5157
cmd = "bugzilla info --components test-fake-product"
5258
fakebz = tests.mockbackend.make_bz(
5359
product_get_args=argsprefix + "components.txt",
54-
product_get_return=prod_get,
55-
bug_legal_values_args=argsprefix + "components-legalvalues.txt",
56-
bug_legal_values_return=legal_values)
60+
product_get_return=prod_get_comp_active)
5761
out = run_cli(cmd, fakebz)
5862
tests.utils.diff_compare(out, cliprefix + "components.txt")
5963

6064
# info --components --active-components
6165
cmd = "bugzilla info --components test-fake-product --active-components"
62-
prod_get_comp_active = {'products': [
63-
{'id': 7, 'name': 'test-fake-product',
64-
'components': [
65-
{'is_active': True, 'name': 'backend/kernel'},
66-
{'is_active': True, 'name': 'client-interfaces'},
67-
]},
68-
]}
6966
fakebz = tests.mockbackend.make_bz(
7067
product_get_args=argsprefix + "components-active.txt",
7168
product_get_return=prod_get_comp_active)

0 commit comments

Comments
 (0)