Skip to content

Commit dd5f480

Browse files
committed
Checkable: Extract parents directly from dependency groups
1 parent 16802e5 commit dd5f480

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/icinga/checkable-dependency.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,8 @@ bool Checkable::AffectsChildren() const
244244
std::set<Checkable::Ptr> Checkable::GetParents() const
245245
{
246246
std::set<Checkable::Ptr> parents;
247-
248-
for (const Dependency::Ptr& dep : GetDependencies()) {
249-
Checkable::Ptr parent = dep->GetParent();
250-
251-
if (parent && parent.get() != this)
252-
parents.insert(parent);
247+
for (auto& dependencyGroup : GetDependencyGroups()) {
248+
dependencyGroup->LoadParents(parents);
253249
}
254250

255251
return parents;

lib/icinga/dependency-group.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ std::vector<Dependency::Ptr> DependencyGroup::GetMembers(const Checkable* child)
153153
return members;
154154
}
155155

156+
/**
157+
* Load all parent Checkables of the current dependency group members.
158+
*
159+
* @param parents The set to load the parent Checkables into.
160+
*/
161+
void DependencyGroup::LoadParents(std::set<Checkable::Ptr>& parents) const
162+
{
163+
std::lock_guard lock(m_Mutex);
164+
for (auto& [_, dependencies] : m_Members) {
165+
VERIFY(!dependencies.empty()); // We should never have an empty map for any given key at any given time.
166+
parents.insert(dependencies.begin()->second->GetParent());
167+
}
168+
}
169+
156170
/**
157171
* Retrieve the number of members in the current dependency group.
158172
*

lib/icinga/dependency.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class DependencyGroup final : public SharedObject
152152
void AddMember(const Dependency::Ptr& member);
153153
void RemoveMember(const Dependency::Ptr& member);
154154
std::vector<Dependency::Ptr> GetMembers(const Checkable* child) const;
155+
void LoadParents(std::set<Checkable::Ptr>& parents) const;
155156
size_t GetMemberCount() const;
156157

157158
void SetIcingaDBIdentifier(const String& identifier);

0 commit comments

Comments
 (0)