Merge "Remove redundant join in _anchors_for_sharing_providers"

This commit is contained in:
Zuul 2018-07-31 18:28:38 +00:00 committed by Gerrit Code Review
commit c90d6101f4
2 changed files with 12 additions and 5 deletions

View File

@ -471,13 +471,14 @@ def _anchors_for_sharing_providers(context, rp_ids, get_id=False):
join_chain = sa.join(
join_chain, shr_with_sps,
shr_with_sps_aggs.c.resource_provider_id == shr_with_sps.c.id)
# TODO(efried): Change this to an inner join when we are sure all
# root_provider_id values are NOT NULL
join_chain = sa.outerjoin(
join_chain, rps, shr_with_sps.c.root_provider_id == rps.c.id)
if get_id:
sel = sa.select([sps.c.id, func.coalesce(rps.c.id, shr_with_sps.c.id)])
sel = sa.select([sps.c.id, func.coalesce(
shr_with_sps.c.root_provider_id, shr_with_sps.c.id)])
else:
# TODO(efried): Change this to an inner join when we are sure all
# root_provider_id values are NOT NULL
join_chain = sa.outerjoin(
join_chain, rps, shr_with_sps.c.root_provider_id == rps.c.id)
sel = sa.select([sps.c.uuid, func.coalesce(rps.c.uuid,
shr_with_sps.c.uuid)])
sel = sel.select_from(join_chain)

View File

@ -1047,6 +1047,12 @@ class TestResourceProviderAggregates(tb.PlacementDbBaseTestCase):
self.assertItemsEqual(
expected, rp_obj._anchors_for_sharing_providers(self.ctx, [s1.id]))
# Get same result (id format) when we set get_id=True
expected = set([(s1.id, rp.id) for rp in (s1, r1, r2, r3, s5)])
self.assertItemsEqual(
expected, rp_obj._anchors_for_sharing_providers(self.ctx, [s1.id],
get_id=True))
# s2 gets s2 (self) and r3 via agg4
expected = set([(s2.uuid, rp.uuid) for rp in (s2, r3)])
self.assertItemsEqual(