Merge "Optimize 'get_artifact_type' from ArtifactRegistry"
This commit is contained in:
commit
38bb4181cb
@ -89,6 +89,8 @@ class ArtifactRegistry(vo_base.VersionedObjectRegistry):
|
|||||||
returning appropriate artifact types based on artifact type name.
|
returning appropriate artifact types based on artifact type name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
enabled_types = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register_all_artifacts(cls):
|
def register_all_artifacts(cls):
|
||||||
"""Register all artifacts in Glare."""
|
"""Register all artifacts in Glare."""
|
||||||
@ -116,6 +118,10 @@ class ArtifactRegistry(vo_base.VersionedObjectRegistry):
|
|||||||
else:
|
else:
|
||||||
raise exception.TypeNotFound(name=type_name)
|
raise exception.TypeNotFound(name=type_name)
|
||||||
|
|
||||||
|
# Fill enabled_types
|
||||||
|
for name, af_type in cls.obj_classes().items():
|
||||||
|
cls.enabled_types[af_type[0].get_type_name()] = af_type[0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_artifact_type(cls, type_name):
|
def get_artifact_type(cls, type_name):
|
||||||
"""Return artifact type based on artifact type name.
|
"""Return artifact type based on artifact type name.
|
||||||
@ -123,10 +129,9 @@ class ArtifactRegistry(vo_base.VersionedObjectRegistry):
|
|||||||
:param type_name: name of artifact type
|
:param type_name: name of artifact type
|
||||||
:return: artifact class
|
:return: artifact class
|
||||||
"""
|
"""
|
||||||
for name, af_type in cls.obj_classes().items():
|
if type_name not in cls.enabled_types:
|
||||||
if af_type[0].get_type_name() == type_name:
|
raise exception.TypeNotFound(name=type_name)
|
||||||
return af_type[0]
|
return cls.enabled_types[type_name]
|
||||||
raise exception.TypeNotFound(name=type_name)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def reset_registry(cls):
|
def reset_registry(cls):
|
||||||
|
Loading…
Reference in New Issue
Block a user