diff --git a/lib/icinga/checkable-dependency.cpp b/lib/icinga/checkable-dependency.cpp index 51e054e60..b82aebc88 100644 --- a/lib/icinga/checkable-dependency.cpp +++ b/lib/icinga/checkable-dependency.cpp @@ -250,12 +250,8 @@ bool Checkable::AffectsChildren() const std::set Checkable::GetParents() const { std::set parents; - - for (const Dependency::Ptr& dep : GetDependencies()) { - Checkable::Ptr parent = dep->GetParent(); - - if (parent && parent.get() != this) - parents.insert(parent); + for (auto& dependencyGroup : GetDependencyGroups()) { + dependencyGroup->LoadParents(parents); } return parents; diff --git a/lib/icinga/dependency-group.cpp b/lib/icinga/dependency-group.cpp index 47e43316f..01520467e 100644 --- a/lib/icinga/dependency-group.cpp +++ b/lib/icinga/dependency-group.cpp @@ -133,6 +133,20 @@ std::vector DependencyGroup::GetDependenciesForChild(const Chec return dependencies; } +/** + * Load all parent Checkables of the current dependency group. + * + * @param parents The set to load the parent Checkables into. + */ +void DependencyGroup::LoadParents(std::set& parents) const +{ + std::lock_guard lock(m_Mutex); + for (auto& [compositeKey, children] : m_Members) { + ASSERT(!children.empty()); // We should never have an empty map for any given key at any given time. + parents.insert(std::get<0>(compositeKey)); + } +} + /** * Retrieve the number of dependency objects in the current dependency group. * diff --git a/lib/icinga/dependency.hpp b/lib/icinga/dependency.hpp index a46b785c4..fe005dbb2 100644 --- a/lib/icinga/dependency.hpp +++ b/lib/icinga/dependency.hpp @@ -155,6 +155,7 @@ public: void AddDependency(const Dependency::Ptr& dependency); void RemoveDependency(const Dependency::Ptr& dependency); std::vector GetDependenciesForChild(const Checkable* child) const; + void LoadParents(std::set& parents) const; size_t GetDependenciesCount() const; void SetIcingaDBIdentifier(const String& identifier);