[Service#power_state] Avoid update if values match #18445
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of the getter for
Service#power_state
, avoid calling anupdate_attributes
if the value is already what we are going to update it to.This avoids not only some SQL queries, but some YAML serialization that slows down API requests and reports that use this
virtual_attribute
.Note: The changes that introduced the
update_attributes
inpower_state
can be found here:#12963
And provides some context as to why I kept it instead of removing that
update_attributes
.Benchmarks:
These benchmarks are done against the API doing the following request:
And about half of the attributes need to trigger an update. Because of the way the code is configured and that the metrics were taken against a database that is detached from the provider (the
power_states_match?
call is consistent every time as a result), this happens consistently across runs.Before
After
Also, if you combine this change with the changes is ManageIQ/manageiq-api#557 you will get the following improvements
Links