From 199effb7ef23980bc69f0233ff6d7ee465623f40 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Tue, 6 Apr 2021 19:35:14 +0200 Subject: [PATCH] Improve unfinished object requirements bool check When we need only boolean value for unfinished object requirements then we don't need to determine the whole list of unfinished objects. --- cdist/config.py | 12 +++++++----- cdist/core/cdist_object.py | 13 ++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index adc460de..f7da9b1d 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -537,7 +537,7 @@ class Config: objects_changed = False for cdist_object in self.object_list(): - if cdist_object.requirements_unfinished( + if cdist_object.has_requirements_unfinished( cdist_object.requirements): """We cannot do anything for this poor object""" continue @@ -548,7 +548,7 @@ class Config: self.object_prepare(cdist_object) objects_changed = True - if cdist_object.requirements_unfinished( + if cdist_object.has_requirements_unfinished( cdist_object.autorequire): """The previous step created objects we depend on - wait for them @@ -567,7 +567,8 @@ class Config: cargo = [] for cdist_object in self.object_list(): - if cdist_object.requirements_unfinished(cdist_object.requirements): + if cdist_object.has_requirements_unfinished( + cdist_object.requirements): """We cannot do anything for this poor object""" continue @@ -621,12 +622,13 @@ class Config: del cargo[:] for cdist_object in self.object_list(): - if cdist_object.requirements_unfinished(cdist_object.requirements): + if cdist_object.has_requirements_unfinished( + cdist_object.requirements): """We cannot do anything for this poor object""" continue if cdist_object.state == core.CdistObject.STATE_PREPARED: - if cdist_object.requirements_unfinished( + if cdist_object.has_requirements_unfinished( cdist_object.autorequire): """The previous step created objects we depend on - wait for them diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py index ccf7392d..bb3a65bd 100644 --- a/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -280,7 +280,7 @@ class CdistObject: '{}: {}').format(self, error)) def requirements_unfinished(self, requirements): - """Return state whether requirements are satisfied""" + """Return unsatisfied requirements""" object_list = [] @@ -291,3 +291,14 @@ class CdistObject: object_list.append(cdist_object) return object_list + + def has_requirements_unfinished(self, requirements): + """Return whether requirements are satisfied""" + + for requirement in requirements: + cdist_object = self.object_from_name(requirement) + + if cdist_object.state != self.STATE_DONE: + return True + + return False