From 7e35b183f925ad744cfcff5f405df131ad1d5f66 Mon Sep 17 00:00:00 2001
From: Erik Olof Gunnar Andersson <eandersson@blizzard.com>
Date: Mon, 26 Jun 2017 15:31:23 -0700
Subject: Remove unnecessary lazy-loaded queries

This patch removes lazy-load queries to speed up database
operations when using neutron-lbaas.

Change-Id: I9d67f0966561baaefb50ae97b943ff6593e194eb
Closes-Bug: #1706466
---
 neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py |  2 +-
 neutron_lbaas/db/loadbalancer/models.py            | 26 +++++++---------------
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py
index 2fdec66..c84ffbf 100644
--- a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py
+++ b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py
@@ -626,7 +626,7 @@ class LoadBalancerPluginDbv2(base_db.CommonDbMixin,
 
             context.session.add(pool_db)
         context.session.refresh(pool_db.loadbalancer)
-        return data_models.Pool.from_sqlalchemy_model(pool_db)
+        return self.get_pool(context, pool_db.id)
 
     def update_pool(self, context, id, pool):
         with context.session.begin(subtransactions=True):
diff --git a/neutron_lbaas/db/loadbalancer/models.py b/neutron_lbaas/db/loadbalancer/models.py
index fab380e..55f49f9 100644
--- a/neutron_lbaas/db/loadbalancer/models.py
+++ b/neutron_lbaas/db/loadbalancer/models.py
@@ -141,19 +141,16 @@ class LoadBalancer(model_base.BASEV2, model_base.HasId, model_base.HasProject):
         LoadBalancerStatistics,
         uselist=False,
         backref=orm.backref("loadbalancer", uselist=False),
-        cascade="all, delete-orphan",
-        lazy='joined')
+        cascade="all, delete-orphan")
     provider = orm.relationship(
         st_db.ProviderResourceAssociation,
         uselist=False,
-        lazy="joined",
         primaryjoin="LoadBalancer.id==ProviderResourceAssociation.resource_id",
         foreign_keys=[st_db.ProviderResourceAssociation.resource_id],
         # this is only for old API backwards compatibility because when a load
         # balancer is deleted the pool ID should be the same as the load
         # balancer ID and should not be cleared out in this table
-        viewonly=True
-    )
+        viewonly=True)
     flavor_id = sa.Column(sa.String(36), sa.ForeignKey(
         'flavors.id', name='fk_lbaas_loadbalancers_flavors_id'))
 
@@ -188,22 +185,18 @@ class PoolV2(model_base.BASEV2, model_base.HasId, model_base.HasProject):
     operating_status = sa.Column(sa.String(16), nullable=False)
     members = orm.relationship(MemberV2,
                                backref=orm.backref("pool", uselist=False),
-                               cascade="all, delete-orphan",
-                               lazy='joined')
+                               cascade="all, delete-orphan")
     healthmonitor = orm.relationship(
         HealthMonitorV2,
-        backref=orm.backref("pool", uselist=False),
-        lazy='joined')
+        backref=orm.backref("pool", uselist=False))
     session_persistence = orm.relationship(
         SessionPersistenceV2,
         uselist=False,
         backref=orm.backref("pool", uselist=False),
-        cascade="all, delete-orphan",
-        lazy='joined')
+        cascade="all, delete-orphan")
     loadbalancer = orm.relationship(
         LoadBalancer, uselist=False,
-        backref=orm.backref("pools", uselist=True),
-        lazy='joined')
+        backref=orm.backref("pools", uselist=True))
 
     @property
     def root_loadbalancer(self):
@@ -303,8 +296,7 @@ class L7Policy(model_base.BASEV2, model_base.HasId, model_base.HasProject):
         backref=orm.backref("policy")
     )
     redirect_pool = orm.relationship(
-        PoolV2, backref=orm.backref("l7_policies", uselist=True),
-        lazy='joined')
+        PoolV2, backref=orm.backref("l7_policies", uselist=True))
 
     @property
     def root_loadbalancer(self):
@@ -338,7 +330,6 @@ class Listener(model_base.BASEV2, model_base.HasId, model_base.HasProject):
             SNI,
             backref=orm.backref("listener", uselist=False),
             uselist=True,
-            lazy="joined",
             primaryjoin="Listener.id==SNI.listener_id",
             order_by='SNI.position',
             collection_class=orderinglist.ordering_list(
@@ -355,8 +346,7 @@ class Listener(model_base.BASEV2, model_base.HasId, model_base.HasProject):
         PoolV2, backref=orm.backref("listeners"), lazy='joined')
     loadbalancer = orm.relationship(
         LoadBalancer,
-        backref=orm.backref("listeners", uselist=True),
-        lazy='joined')
+        backref=orm.backref("listeners", uselist=True))
     l7_policies = orm.relationship(
         L7Policy,
         uselist=True,
-- 
cgit v1.1

