Only calculate all_binaries_in_suite when necessary

This commit is contained in:
Ivo De Decker 2020-01-29 18:19:14 +00:00
parent 62c309da07
commit 4aa1834cfe

View File

@ -62,12 +62,21 @@ class Suite(object):
@property @property
def binaries(self): def binaries(self):
# TODO some callers modify this structure, which doesn't invalidate
# the self._all_binaries_in_suite cache
return self._binaries return self._binaries
@binaries.setter @binaries.setter
def binaries(self, binaries): def binaries(self, binaries):
self._binaries = binaries self._binaries = binaries
self._all_binaries_in_suite = {x.pkg_id: x for a in binaries for x in binaries[a].values()} self._all_binaries_in_suite = None
@property
def all_binaries_in_suite(self):
if not self._all_binaries_in_suite:
self._all_binaries_in_suite = {x.pkg_id: x for a in self._binaries
for x in self._binaries[a].values()}
return self._all_binaries_in_suite
def any_of_these_are_in_the_suite(self, pkgs): def any_of_these_are_in_the_suite(self, pkgs):
"""Test if at least one package of a given set is in the suite """Test if at least one package of a given set is in the suite
@ -75,7 +84,7 @@ class Suite(object):
:param pkgs: A set of BinaryPackageId :param pkgs: A set of BinaryPackageId
:return: True if any of the packages in pkgs are currently in the suite :return: True if any of the packages in pkgs are currently in the suite
""" """
return not self._all_binaries_in_suite.isdisjoint(pkgs) return not self.all_binaries_in_suite.keys().isdisjoint(pkgs)
def is_pkg_in_the_suite(self, pkg_id): def is_pkg_in_the_suite(self, pkg_id):
"""Test if the package of is in testing """Test if the package of is in testing
@ -83,7 +92,7 @@ class Suite(object):
:param pkg_id: A BinaryPackageId :param pkg_id: A BinaryPackageId
:return: True if the pkg is currently in the suite :return: True if the pkg is currently in the suite
""" """
return pkg_id in self._all_binaries_in_suite return pkg_id in self.all_binaries_in_suite
def which_of_these_are_in_the_suite(self, pkgs): def which_of_these_are_in_the_suite(self, pkgs):
"""Iterate over all packages that are in the suite """Iterate over all packages that are in the suite
@ -91,7 +100,7 @@ class Suite(object):
:param pkgs: An iterable of package ids :param pkgs: An iterable of package ids
:return: An iterable of package ids that are in the suite :return: An iterable of package ids that are in the suite
""" """
yield from (x for x in pkgs if x in self._all_binaries_in_suite) yield from (x for x in pkgs if x in self.all_binaries_in_suite)
class TargetSuite(Suite): class TargetSuite(Suite):
@ -142,7 +151,12 @@ class TargetSuite(Suite):
:param pkg_id The id of the package :param pkg_id The id of the package
""" """
# TODO The calling code currently manually updates the contents of
# target_suite.binaries when this is called. It would probably make
# more sense to do that here instead
self.inst_tester.add_binary(pkg_id) self.inst_tester.add_binary(pkg_id)
self._all_binaries_in_suite = None
def remove_binary(self, pkg_id): def remove_binary(self, pkg_id):
"""Remove a binary from the suite """Remove a binary from the suite
@ -151,7 +165,12 @@ class TargetSuite(Suite):
If the package is not known, this method will throw an If the package is not known, this method will throw an
KeyError. KeyError.
""" """
# TODO The calling code currently manually updates the contents of
# target_suite.binaries when this is called. It would probably make
# more sense to do that here instead
self.inst_tester.remove_binary(pkg_id) self.inst_tester.remove_binary(pkg_id)
self._all_binaries_in_suite = None
def check_suite_source_pkg_consistency(self, comment): def check_suite_source_pkg_consistency(self, comment):
sources_t = self.sources sources_t = self.sources