Use the DB object when listing the SG rules
When listing the security group rules, the DB object can be used instead the OVO. That will save the conversion time. In a development environment with 1000 SG rules, the DB query took around 100 ms and the same time to load the OVOs from the DB objects. The ``NeutronDbObject.get_objects`` now can return the DB objects without converting them to OVO if "return_db_obj=True". Trivial-Fix Change-Id: I245032cf99b1b042226703f5ddb4625e176924c5
This commit is contained in:
parent
81f8524527
commit
d1fa2f104d
|
@ -686,8 +686,6 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
||||||
return sg_id
|
return sg_id
|
||||||
|
|
||||||
def _make_security_group_rule_dict(self, security_group_rule, fields=None):
|
def _make_security_group_rule_dict(self, security_group_rule, fields=None):
|
||||||
|
|
||||||
# TODO(slaweq): switch this to use OVO instead of db object
|
|
||||||
res = {'id': security_group_rule['id'],
|
res = {'id': security_group_rule['id'],
|
||||||
'tenant_id': security_group_rule['tenant_id'],
|
'tenant_id': security_group_rule['tenant_id'],
|
||||||
'security_group_id': security_group_rule['security_group_id'],
|
'security_group_id': security_group_rule['security_group_id'],
|
||||||
|
@ -825,10 +823,10 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
||||||
# be returned
|
# be returned
|
||||||
rule_objs = sg_obj.SecurityGroupRule.get_objects(
|
rule_objs = sg_obj.SecurityGroupRule.get_objects(
|
||||||
context_lib.get_admin_context(), _pager=pager,
|
context_lib.get_admin_context(), _pager=pager,
|
||||||
validate_filters=False, **filters
|
validate_filters=False, return_db_obj=True, **filters
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
self._make_security_group_rule_dict(obj.db_obj, fields)
|
self._make_security_group_rule_dict(obj, fields)
|
||||||
for obj in rule_objs
|
for obj in rule_objs
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -614,7 +614,7 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_objects(cls, context, _pager=None, validate_filters=True,
|
def get_objects(cls, context, _pager=None, validate_filters=True,
|
||||||
fields=None, **kwargs):
|
fields=None, return_db_obj=False, **kwargs):
|
||||||
"""Fetch a list of objects
|
"""Fetch a list of objects
|
||||||
|
|
||||||
Fetch all results from DB and convert them to versioned objects.
|
Fetch all results from DB and convert them to versioned objects.
|
||||||
|
@ -629,6 +629,8 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject):
|
||||||
avoid loading synthetic fields when possible, and
|
avoid loading synthetic fields when possible, and
|
||||||
does not affect db queries. Default is None, which
|
does not affect db queries. Default is None, which
|
||||||
is the same as []. Example: ['id', 'name']
|
is the same as []. Example: ['id', 'name']
|
||||||
|
:param return_db_obj: if 'True', the DB object is returned instead of
|
||||||
|
the OVO, saving the conversion time.
|
||||||
:param kwargs: multiple keys defined by key=value pairs
|
:param kwargs: multiple keys defined by key=value pairs
|
||||||
:return: list of objects of NeutronDbObject class or empty list
|
:return: list of objects of NeutronDbObject class or empty list
|
||||||
"""
|
"""
|
||||||
|
@ -637,6 +639,8 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject):
|
||||||
with cls.db_context_reader(context):
|
with cls.db_context_reader(context):
|
||||||
db_objs = obj_db_api.get_objects(
|
db_objs = obj_db_api.get_objects(
|
||||||
cls, context, _pager=_pager, **cls.modify_fields_to_db(kwargs))
|
cls, context, _pager=_pager, **cls.modify_fields_to_db(kwargs))
|
||||||
|
if return_db_obj:
|
||||||
|
return db_objs
|
||||||
|
|
||||||
return [cls._load_object(context, db_obj, fields=fields)
|
return [cls._load_object(context, db_obj, fields=fields)
|
||||||
for db_obj in db_objs]
|
for db_obj in db_objs]
|
||||||
|
|
Loading…
Reference in New Issue