New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConfigItem::CommitNewItems(): pre-sort types by their load dependencies once #10003
base: master
Are you sure you want to change the base?
Conversation
for (const Type::Ptr& type : Type::GetAllTypes()) { | ||
if (ConfigObject::TypeInstance->IsAssignableFrom(type)) | ||
types.insert(type); | ||
types.emplace_back(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of copying the types around, you can access Type::GetAllTypes()
directly within your new method or pass the types without having to copy them if you need the arguments for your unittest. You can then perform this check below when they are actually loaded.
icinga2/lib/config/configitem.cpp
Lines 456 to 459 in 9726620
for (const Type::Ptr& type : Type::GetAllTypes()) { | |
if (ConfigObject::TypeInstance->IsAssignableFrom(type)) | |
types.emplace_back(type); | |
} |
Lines 85 to 87 in 9726620
for (auto& type : types) { | |
pending.emplace(type.get()); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should address such in
one nice day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't suggesting you to remove this check, I was just pointing out that you are unnecessarily copying around the types and should avoid doing that. It's not something that already existed and simply saying it will be fixed "one nice day" isn't an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not all types are config types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not all types are config types.
Why would that matter to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONFIG items get committed here, of course only CONFIG types are relevant here. Btw. that preserved check IS "something that already existed" (just like #10003 (comment)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/base/type.cpp
Outdated
ready = true; | ||
|
||
for (auto dep : type->GetLoadDependencies()) { | ||
if (loaded.find(dep) == loaded.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've omitted a check from the previous version of the code.
types.find(pLoadDep) != types.end() ---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type::SortByLoadDependencies() auto-includes all load dependencies, so this case vanishes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort functions do not add values, so if it does, the function name is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-added it.
…es once to avoid complicated nested loops, iterating over the same types and checking dependencies over and over, skipping already completed ones.
9726620
to
3ffa26a
Compare
to avoid complicated nested loops, iterating over the same types and
checking dependencies over and over, skipping already completed ones.