mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 06:05:01 +02:00
ConfigItem::CommitNewItems(): pre-sort types by their load dependencies once
to avoid complicated nested loops, iterating over the same types and checking dependencies over and over, skipping already completed ones.
This commit is contained in:
parent
b848934d57
commit
31f3acaa13
@ -444,33 +444,9 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
<< "Committing " << total << " new items.";
|
<< "Committing " << total << " new items.";
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
std::set<Type::Ptr> types;
|
|
||||||
std::set<Type::Ptr> completed_types;
|
|
||||||
int itemsCount {0};
|
int itemsCount {0};
|
||||||
|
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
|
||||||
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
|
|
||||||
types.insert(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (types.size() != completed_types.size()) {
|
|
||||||
for (const Type::Ptr& type : types) {
|
|
||||||
if (completed_types.find(type) != completed_types.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool unresolved_dep = false;
|
|
||||||
|
|
||||||
/* skip this type (for now) if there are unresolved load dependencies */
|
|
||||||
for (auto pLoadDep : type->GetLoadDependencies()) {
|
|
||||||
if (types.find(pLoadDep) != types.end() && completed_types.find(pLoadDep) == completed_types.end()) {
|
|
||||||
unresolved_dep = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unresolved_dep)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::atomic<int> committed_items(0);
|
std::atomic<int> committed_items(0);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -501,8 +477,6 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
|
|
||||||
itemsCount += committed_items;
|
itemsCount += committed_items;
|
||||||
|
|
||||||
completed_types.insert(type);
|
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
if (committed_items > 0)
|
if (committed_items > 0)
|
||||||
Log(LogDebug, "configitem")
|
Log(LogDebug, "configitem")
|
||||||
@ -512,33 +486,13 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
if (upq.HasExceptions())
|
if (upq.HasExceptions())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
Log(LogDebug, "configitem")
|
Log(LogDebug, "configitem")
|
||||||
<< "Committed " << itemsCount << " items.";
|
<< "Committed " << itemsCount << " items.";
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
completed_types.clear();
|
for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
|
||||||
|
|
||||||
while (types.size() != completed_types.size()) {
|
|
||||||
for (const Type::Ptr& type : types) {
|
|
||||||
if (completed_types.find(type) != completed_types.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool unresolved_dep = false;
|
|
||||||
|
|
||||||
/* skip this type (for now) if there are unresolved load dependencies */
|
|
||||||
for (auto pLoadDep : type->GetLoadDependencies()) {
|
|
||||||
if (types.find(pLoadDep) != types.end() && completed_types.find(pLoadDep) == completed_types.end()) {
|
|
||||||
unresolved_dep = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unresolved_dep)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::atomic<int> notified_items(0);
|
std::atomic<int> notified_items(0);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -574,8 +528,6 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
completed_types.insert(type);
|
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
if (notified_items > 0)
|
if (notified_items > 0)
|
||||||
Log(LogDebug, "configitem")
|
Log(LogDebug, "configitem")
|
||||||
@ -618,7 +570,6 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
if (!CommitNewItems(context, upq, newItems))
|
if (!CommitNewItems(context, upq, newItems))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user