Merge pull request #13072 from Yannig/devel_cache_optimization
Cache optimization
This commit is contained in:
commit
e36b4e2a13
1 changed files with 9 additions and 0 deletions
|
@ -37,6 +37,8 @@ from ansible.playbook.attribute import Attribute, FieldAttribute
|
||||||
from ansible.utils.boolean import boolean
|
from ansible.utils.boolean import boolean
|
||||||
from ansible.utils.vars import combine_vars, isidentifier
|
from ansible.utils.vars import combine_vars, isidentifier
|
||||||
|
|
||||||
|
BASE_ATTRIBUTES = {}
|
||||||
|
|
||||||
class Base:
|
class Base:
|
||||||
|
|
||||||
# connection/transport
|
# connection/transport
|
||||||
|
@ -123,12 +125,19 @@ class Base:
|
||||||
Returns the list of attributes for this class (or any subclass thereof).
|
Returns the list of attributes for this class (or any subclass thereof).
|
||||||
If the attribute name starts with an underscore, it is removed
|
If the attribute name starts with an underscore, it is removed
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# check cache before retrieving attributes
|
||||||
|
if self.__class__ in BASE_ATTRIBUTES:
|
||||||
|
return BASE_ATTRIBUTES[self.__class__]
|
||||||
|
|
||||||
|
# Cache init
|
||||||
base_attributes = dict()
|
base_attributes = dict()
|
||||||
for (name, value) in getmembers(self.__class__):
|
for (name, value) in getmembers(self.__class__):
|
||||||
if isinstance(value, Attribute):
|
if isinstance(value, Attribute):
|
||||||
if name.startswith('_'):
|
if name.startswith('_'):
|
||||||
name = name[1:]
|
name = name[1:]
|
||||||
base_attributes[name] = value
|
base_attributes[name] = value
|
||||||
|
BASE_ATTRIBUTES[self.__class__] = base_attributes
|
||||||
return base_attributes
|
return base_attributes
|
||||||
|
|
||||||
def _initialize_base_attributes(self):
|
def _initialize_base_attributes(self):
|
||||||
|
|
Loading…
Reference in a new issue