Avoid iterating over all of the segment data just for counting
getting the full collection (which includes iterating over it and populating attributes) just to gather the count of it is wasteful. we can just use the count api. Change-Id: I1b216cb2c8c5b612f12554454d5721a14975f138 Closes-Bug: #1821708
This commit is contained in:
parent
c70a935ce7
commit
04f23958e6
@ -442,6 +442,9 @@ class SegmentHostRoutes(object):
|
||||
def _get_subnets(self, context, network_id):
|
||||
return subnet_obj.Subnet.get_objects(context, network_id=network_id)
|
||||
|
||||
def _count_subnets(self, context, network_id):
|
||||
return subnet_obj.Subnet.count(context, network_id=network_id)
|
||||
|
||||
def _calculate_routed_network_host_routes(self, context, ip_version,
|
||||
network_id=None, subnet_id=None,
|
||||
segment_id=None,
|
||||
@ -596,7 +599,8 @@ class SegmentHostRoutes(object):
|
||||
subnet = kwargs['subnet']
|
||||
# If there are other subnets on the network and subnet has segment_id
|
||||
# ensure host routes for all subnets are updated.
|
||||
if (len(self._get_subnets(context, subnet['network_id'])) > 1 and
|
||||
|
||||
if (self._count_subnets(context, subnet['network_id']) > 1 and
|
||||
subnet.get('segment_id')):
|
||||
self._update_routed_network_host_routes(context,
|
||||
subnet['network_id'])
|
||||
|
Loading…
Reference in New Issue
Block a user