Fixes inefficiency in quantum.api.v2.base._filters

Use iteritems() instead of getall() on request.GET

Fixes bug #1092995

Change-Id: Ic0b5e3d7c7b1ddd072d9fe918ea22a8e9aef9ee4
This commit is contained in:
Zhongyue Luo 2012-12-22 06:26:05 +08:00
parent eef903f64b
commit 6618270b68

View File

@ -63,28 +63,17 @@ def _filters(request, attr_info):
{'check': [u'a', u'b'], 'name': [u'Bob']} {'check': [u'a', u'b'], 'name': [u'Bob']}
""" """
res = {} res = {}
for key in set(request.GET): for key, values in request.GET.dict_of_lists().iteritems():
if key == 'fields': if key == 'fields':
continue continue
values = [v for v in request.GET.getall(key) if v] values = [v for v in values if v]
if not values: key_attr_info = attr_info.get(key, {})
continue if 'convert_list_to' in key_attr_info:
key_attr_info = attr_info.get(key) values = key_attr_info['convert_list_to'](values)
if not key_attr_info: elif 'convert_to' in key_attr_info:
res[key] = values convert_to = key_attr_info['convert_to']
continue values = [convert_to(v) for v in values]
convert_list_to = key_attr_info.get('convert_list_to') if values:
if not convert_list_to:
convert_to = key_attr_info.get('convert_to')
if convert_to:
convert_list_to = lambda values_: [convert_to(x)
for x in values_]
else:
convert_list_to = lambda values_: None
result_values = convert_list_to(values)
if result_values:
res[key] = result_values
else:
res[key] = values res[key] = values
return res return res