Skip to content

Commit 5b56433

Browse files
committed
Checkable: Extract parents directly from dependency groups
1 parent 098a424 commit 5b56433

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/icinga/checkable-dependency.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,8 @@ bool Checkable::AffectsChildren(const CheckResult::Ptr& cr) const
248248
std::set<Checkable::Ptr> Checkable::GetParents() const
249249
{
250250
std::set<Checkable::Ptr> parents;
251-
252-
for (const Dependency::Ptr& dep : GetDependencies()) {
253-
Checkable::Ptr parent = dep->GetParent();
254-
255-
if (parent && parent.get() != this)
256-
parents.insert(parent);
251+
for (auto& dependencyGroup : GetDependencyGroups()) {
252+
dependencyGroup->LoadParents(parents);
257253
}
258254

259255
return parents;

lib/icinga/dependency-group.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ std::vector<Dependency::Ptr> DependencyGroup::GetDependenciesForChild(const Chec
146146
return dependencies;
147147
}
148148

149+
/**
150+
* Load all parent Checkables of the current dependency group.
151+
*
152+
* @param parents The set to load the parent Checkables into.
153+
*/
154+
void DependencyGroup::LoadParents(std::set<Checkable::Ptr>& parents) const
155+
{
156+
std::lock_guard lock(m_Mutex);
157+
for (auto& [compositeKey, children] : m_Members) {
158+
ASSERT(!children.empty()); // We should never have an empty map for any given key at any given time.
159+
parents.insert(std::get<0>(compositeKey));
160+
}
161+
}
162+
149163
/**
150164
* Retrieve the number of dependency objects in the current dependency group.
151165
*

lib/icinga/dependency.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class DependencyGroup final : public SharedObject
148148
void AddDependency(const Dependency::Ptr& dependency);
149149
void RemoveDependency(const Dependency::Ptr& dependency);
150150
std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const;
151+
void LoadParents(std::set<Checkable::Ptr>& parents) const;
151152
size_t GetDependenciesCount() const;
152153

153154
void SetIcingaDBIdentifier(const String& identifier);

0 commit comments

Comments
 (0)