diff --git a/octodns/manager.py b/octodns/manager.py index 2977aaf..566b979 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -228,37 +228,7 @@ class Manager(object): 'Incorrect plan_output config for ' + plan_output_name ) - self._zone_tree = None - - @property - def zone_tree(self): - if self._zone_tree is None: - zone_tree = {} - - # Get a list of all of our zone names. Sort them from shortest to - # longest so that parents will always come before their subzones - zones = sorted( - self.config['zones'].keys(), key=lambda z: len(z), reverse=True - ) - zones = deque(zones) - # Until we're done processing zones - while zones: - # Grab the one we'lre going to work on now - zone = zones.pop() - trimmer = len(zone) + 1 - subs = set() - # look at all the zone names that come after it - for candidate in zones: - # If they end with this zone's name them they're a sub - if candidate.endswith(zone): - # We want subs to exclude the zone portion - subs.add(candidate[:-trimmer]) - - zone_tree[zone] = subs - - self._zone_tree = zone_tree - - return self._zone_tree + self._configured_sub_zones = None def _try_version(self, module_name, module=None, version=None): try: @@ -330,7 +300,35 @@ class Manager(object): return kwargs def configured_sub_zones(self, zone_name): - return self.zone_tree.get(zone_name, set()) + if self._configured_sub_zones is None: + # First time through we compute all the sub-zones + + configured_sub_zones = {} + + # Get a list of all of our zone names. Sort them from shortest to + # longest so that parents will always come before their subzones + zones = sorted( + self.config['zones'].keys(), key=lambda z: len(z), reverse=True + ) + zones = deque(zones) + # Until we're done processing zones + while zones: + # Grab the one we'lre going to work on now + zone = zones.pop() + trimmer = len(zone) + 1 + subs = set() + # look at all the zone names that come after it + for candidate in zones: + # If they end with this zone's name them they're a sub + if candidate.endswith(zone): + # We want subs to exclude the zone portion + subs.add(candidate[:-trimmer]) + + configured_sub_zones[zone] = subs + + self._configured_sub_zones = configured_sub_zones + + return self._configured_sub_zones.get(zone_name, set()) def _populate_and_plan( self, diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index 7a1b58d..e3a5a50 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -723,15 +723,6 @@ class TestManager(TestCase): 'skipped.alevel.unit.tests.': {}, } - self.assertEqual( - { - 'unit.tests.': {'sub', 'another.sub', 'skipped.alevel'}, - 'sub.unit.tests.': {'another'}, - 'another.sub.unit.tests.': set(), - 'skipped.alevel.unit.tests.': set(), - }, - manager.zone_tree, - ) self.assertEqual( {'another.sub', 'sub', 'skipped.alevel'}, manager.configured_sub_zones('unit.tests.'), @@ -757,20 +748,7 @@ class TestManager(TestCase): 'skipped.alevel.unit.tests.': {}, 'skipped.alevel.unit2.tests.': {}, } - manager._zone_tree = None - self.assertEqual( - { - 'unit.tests.': {'sub', 'another.sub', 'skipped.alevel'}, - 'sub.unit.tests.': {'another'}, - 'another.sub.unit.tests.': set(), - 'skipped.alevel.unit.tests.': set(), - 'unit2.tests.': {'sub', 'another.sub', 'skipped.alevel'}, - 'sub.unit2.tests.': {'another'}, - 'another.sub.unit2.tests.': set(), - 'skipped.alevel.unit2.tests.': set(), - }, - manager.zone_tree, - ) + manager._configured_sub_zones = None self.assertEqual( {'another.sub', 'sub', 'skipped.alevel'}, manager.configured_sub_zones('unit.tests.'),