]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Set loading strategy to joined for Routerport/Port
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 10:36:50 +0000 (03:36 -0700)
committerKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 10:36:50 +0000 (03:36 -0700)
The RouterPort model has a relationship to the ports model which
is frequently relied on to get the port IDs of interfaces attached
to a router. However, this defaults to the loading strategy to
'select', which meant a new query was being emitted for every
interface to the ports table just to get the ID.

This patch adjusts the relationship to be 'joined' by default so
one query will fetch the related ports.

Another option would have been not to use the port object at all since
the ID is all that the callers were usually interested in. However,
they would end up using the ID to do a port lookup, which is being
optimized away in another patch anyway so the full port object from
the relationship will end up getting used.

Change-Id: Id1ae35f845f7367d5f1f065c6fa637da7b980a2b
Partial-Bug: #1445412

neutron/db/l3_db.py

index bc549937b4ea4a8764655ce2ce3afa5d265e096e..5ceb9030e3beeff75c914334ea7cb37343227e1b 100644 (file)
@@ -71,7 +71,8 @@ class RouterPort(model_base.BASEV2):
     port_type = sa.Column(sa.String(255))
     port = orm.relationship(
         models_v2.Port,
-        backref=orm.backref('routerport', uselist=False, cascade="all,delete"))
+        backref=orm.backref('routerport', uselist=False, cascade="all,delete"),
+        lazy='joined')
 
 
 class Router(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):