Fix database loading for some resources
Whenever we use share network subnets, we'd always need the associated share networks; so 'joined' loading them makes sense rather than lazy loading. Same is true for Share Group Snapshots, since share group attributes are relevant in contexts that snapshots are referenced. Fix the ORM relationship loading technique and queries appropriately. Also convert share network name into a property of the share network subnet class. Co-Authored-By: Carlos Eduardo <ces.eduardo98@gmail.com> Closes-Bug: #1862833 Change-Id: I8c29760479f9c874d618e2c15ebab75bffeb3cbb
This commit is contained in:
parent
198774292d
commit
ef6b9a0c72
manila
releasenotes/notes
@ -37,7 +37,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
'id': share_network_subnet.get('id'),
|
||||
'availability_zone': share_network_subnet.get('availability_zone'),
|
||||
'share_network_id': share_network_subnet.get('share_network_id'),
|
||||
'share_network_name': share_network_subnet.share_network['name'],
|
||||
'share_network_name': share_network_subnet['share_network_name'],
|
||||
'created_at': share_network_subnet.get('created_at'),
|
||||
'segmentation_id': share_network_subnet.get('segmentation_id'),
|
||||
'neutron_subnet_id': share_network_subnet.get('neutron_subnet_id'),
|
||||
|
@ -43,6 +43,7 @@ import six
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.orm import subqueryload
|
||||
from sqlalchemy.sql.expression import literal
|
||||
from sqlalchemy.sql.expression import true
|
||||
from sqlalchemy.sql import func
|
||||
@ -3400,7 +3401,7 @@ def _network_get_query(context, session=None):
|
||||
return (model_query(context, models.ShareNetwork, session=session).
|
||||
options(joinedload('share_instances'),
|
||||
joinedload('security_services'),
|
||||
joinedload('share_network_subnets')))
|
||||
subqueryload('share_network_subnets')))
|
||||
|
||||
|
||||
@require_context
|
||||
@ -3543,7 +3544,7 @@ def _network_subnet_get_query(context, session=None):
|
||||
if session is None:
|
||||
session = get_session()
|
||||
return (model_query(context, models.ShareNetworkSubnet, session=session).
|
||||
options(joinedload('share_servers')))
|
||||
options(joinedload('share_servers'), joinedload('share_network')))
|
||||
|
||||
|
||||
@require_context
|
||||
|
@ -938,7 +938,9 @@ class ShareNetwork(BASE, ManilaBase):
|
||||
'ShareNetwork.id == ShareInstance.share_network_id,'
|
||||
'ShareInstance.deleted == "False")')
|
||||
share_network_subnets = orm.relationship(
|
||||
"ShareNetworkSubnet", backref='share_network', lazy='immediate',
|
||||
"ShareNetworkSubnet",
|
||||
lazy='joined',
|
||||
backref=orm.backref('share_network', lazy='joined'),
|
||||
primaryjoin='and_'
|
||||
'(ShareNetwork.id == ShareNetworkSubnet.share_network_id,'
|
||||
'ShareNetworkSubnet.deleted == "False")')
|
||||
@ -990,6 +992,10 @@ class ShareNetworkSubnet(BASE, ManilaBase):
|
||||
def is_default(self):
|
||||
return self.availability_zone_id is None
|
||||
|
||||
@property
|
||||
def share_network_name(self):
|
||||
return self.share_network['name']
|
||||
|
||||
|
||||
class ShareServer(BASE, ManilaBase):
|
||||
"""Represents share server used by share."""
|
||||
@ -1216,7 +1222,7 @@ class ShareGroupSnapshot(BASE, ManilaBase):
|
||||
status = Column(String(255))
|
||||
share_group = orm.relationship(
|
||||
ShareGroup,
|
||||
backref="snapshots",
|
||||
backref=orm.backref("snapshots", lazy='joined'),
|
||||
foreign_keys=share_group_id,
|
||||
primaryjoin=('and_('
|
||||
'ShareGroupSnapshot.share_group_id == ShareGroup.id,'
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Some resources will be eagerly loaded from the database to avoid cyclical
|
||||
references and faulty results if their retrieval is deferred.
|
Loading…
Reference in New Issue
Block a user