Checkable: Extract parents directly from dependency groups

This commit is contained in:
Yonas Habteab 2025-02-10 08:30:32 +01:00
parent 806fff950c
commit 8640a3f84e
3 changed files with 17 additions and 6 deletions

View File

@ -250,12 +250,8 @@ bool Checkable::AffectsChildren() const
std::set<Checkable::Ptr> Checkable::GetParents() const std::set<Checkable::Ptr> Checkable::GetParents() const
{ {
std::set<Checkable::Ptr> parents; std::set<Checkable::Ptr> parents;
for (auto& dependencyGroup : GetDependencyGroups()) {
for (const Dependency::Ptr& dep : GetDependencies()) { dependencyGroup->LoadParents(parents);
Checkable::Ptr parent = dep->GetParent();
if (parent && parent.get() != this)
parents.insert(parent);
} }
return parents; return parents;

View File

@ -133,6 +133,20 @@ std::vector<Dependency::Ptr> DependencyGroup::GetDependenciesForChild(const Chec
return dependencies; 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<Checkable::Ptr>& 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. * Retrieve the number of dependency objects in the current dependency group.
* *

View File

@ -155,6 +155,7 @@ public:
void AddDependency(const Dependency::Ptr& dependency); void AddDependency(const Dependency::Ptr& dependency);
void RemoveDependency(const Dependency::Ptr& dependency); void RemoveDependency(const Dependency::Ptr& dependency);
std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const; std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const;
void LoadParents(std::set<Checkable::Ptr>& parents) const;
size_t GetDependenciesCount() const; size_t GetDependenciesCount() const;
void SetIcingaDBIdentifier(const String& identifier); void SetIcingaDBIdentifier(const String& identifier);