better performance in find_firsts
_is_build_cache not set in dictionary storage
This commit is contained in:
@ -313,7 +313,7 @@ class SubConfig(object):
|
||||
|
||||
def _find(self, bytype, byname, byvalue, first, type_='option',
|
||||
_subpath=None, check_properties=True, display_error=True,
|
||||
force_permissive=False):
|
||||
force_permissive=False, only_path=undefined):
|
||||
"""
|
||||
convenience method for finding an option that lives only in the subtree
|
||||
|
||||
@ -341,9 +341,15 @@ class SubConfig(object):
|
||||
# if value and/or check_properties are set, need all avalaible option
|
||||
# If first one has no good value or not good property check second one
|
||||
# and so on
|
||||
only_first = first is True and byvalue is None and check_properties is None
|
||||
options = self.cfgimpl_get_description().impl_get_options_paths(
|
||||
bytype, byname, _subpath, only_first, self._cfgimpl_get_context())
|
||||
only_first = first is True and byvalue is None and \
|
||||
check_properties is None
|
||||
if only_path is not undefined:
|
||||
option = self.unwrap_from_path(only_path)
|
||||
options = [(only_path, option)]
|
||||
else:
|
||||
options = self.cfgimpl_get_description().impl_get_options_paths(
|
||||
bytype, byname, _subpath, only_first,
|
||||
self._cfgimpl_get_context())
|
||||
for path, option in options:
|
||||
if not _filter_by_value():
|
||||
continue
|
||||
@ -670,15 +676,15 @@ class GroupConfig(_CommonConfig):
|
||||
except PropertiesOptionError:
|
||||
pass
|
||||
|
||||
def find_firsts(self, byname=None, bypath=None, byvalue=undefined,
|
||||
type_='path', display_error=True):
|
||||
def find_firsts(self, byname=None, bypath=undefined, byvalue=undefined,
|
||||
type_='option', display_error=True):
|
||||
"""Find first not in current GroupConfig, but in each children
|
||||
"""
|
||||
ret = []
|
||||
#if MetaConfig, all children have same OptionDescription as context
|
||||
#so search only one time for all children
|
||||
#if MetaConfig, all children have same OptionDescription in context
|
||||
#so search only one time the option for all children
|
||||
try:
|
||||
if bypath is None and byname is not None and \
|
||||
if bypath is undefined and byname is not None and \
|
||||
isinstance(self, MetaConfig):
|
||||
bypath = self._find(bytype=None, byvalue=undefined, byname=byname,
|
||||
first=True, type_='path',
|
||||
@ -686,33 +692,27 @@ class GroupConfig(_CommonConfig):
|
||||
display_error=display_error)
|
||||
byname = None
|
||||
except AttributeError:
|
||||
pass
|
||||
return self._find_return_results([], True)
|
||||
for child in self._impl_children:
|
||||
try:
|
||||
if not isinstance(child, MetaConfig):
|
||||
if bypath is not None:
|
||||
#if byvalue is None, try if not raise
|
||||
value = getattr(child, bypath)
|
||||
if byvalue is not undefined:
|
||||
if isinstance(value, Multi):
|
||||
if byvalue in value:
|
||||
ret.append(child)
|
||||
else:
|
||||
if value == byvalue:
|
||||
ret.append(child)
|
||||
else:
|
||||
ret.append(child)
|
||||
else:
|
||||
ret.append(child.find_first(byname=byname,
|
||||
byvalue=byvalue,
|
||||
type_=type_,
|
||||
display_error=False))
|
||||
else:
|
||||
if isinstance(child, GroupConfig):
|
||||
ret.extend(child.find_firsts(byname=byname,
|
||||
bypath=bypath,
|
||||
byvalue=byvalue,
|
||||
type_=type_,
|
||||
display_error=False))
|
||||
else:
|
||||
if type_ == 'config':
|
||||
f_type = 'path'
|
||||
else:
|
||||
f_type = type_
|
||||
f_ret = child._find(None, byname, byvalue, first=True,
|
||||
type_=f_type, display_error=False,
|
||||
only_path=bypath)
|
||||
if type_ == 'config':
|
||||
ret.append(child)
|
||||
else:
|
||||
ret.append(f_ret)
|
||||
except AttributeError:
|
||||
pass
|
||||
return self._find_return_results(ret, display_error)
|
||||
|
@ -399,6 +399,7 @@ class StorageOptionDescription(StorageBase):
|
||||
_currpath.pop()
|
||||
if save:
|
||||
self._cache_paths = (tuple(cache_option), tuple(cache_path))
|
||||
self._is_build_cache = True
|
||||
|
||||
def impl_get_options_paths(self, bytype, byname, _subpath, only_first, context):
|
||||
find_results = []
|
||||
|
Reference in New Issue
Block a user