-
Notifications
You must be signed in to change notification settings - Fork 897
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
Fix cached query for total unregistered vms #16577
Fix cached query for total unregistered vms #16577
Conversation
according to Vm#un_registered?
@lpichler Cannot apply the following label because they are not recognized: gapridashivili/yes |
@miq-bot add_label gaprindashivili/yes |
@lpichler Cannot apply the following label because they are not recognized: gaprindashivili/yes |
@miq-bot add_label gaprindashvili/yes |
@lpichler Cannot apply the following label because they are not recognized: gaprindashivili/yes |
Good eye.
The logic: Templates must have an EMS, but all others just need a host. class VmOrTemplate
def registered?
return false if self.template? && ext_management_system_id.nil?
host_id.present?
end
end If we are querying class VmOrTemplate
def registered?
host_id.present?
end
end So unregistered becomes: cache_with_timeout(:unregistered_vm_counts_by_storage_id, 15.seconds) do
Vm.not(:host_id => nil)
.group("storage_id").pluck("storage_id, COUNT(*) AS vm_count")
.each_with_object(Hash.new(0)) { |(storage_id, count), h| h[storage_id] = count.to_i }
end Also fun. (sorry) Think the cache_with_timeout(:unregistered_vm_counts_by_storage_id, 15.seconds) do
Vm.not(:host_id => nil).group("storage_id").count
.each_with_object(Hash.new(0)) { |(storage_id, count), h| h[storage_id] = count.to_i }
end |
we have definition of registered: class VmOrTemplate def registered? return false if self.template? && ext_management_system_id.nil? host_id.present? end end this query is using only Vm, we can remove part template = true and according to the rule upper we are not taking into account ems_id when it is Vm. so we can remove also part vms.ems_id IS NULL
When we are using this method, we always going thru existing Storage object
yes, that's right, awesome, thanks ! I filtered out also vms without storages because to use this method we need always existing storage - so it was useless. |
Checked commits lpichler/manageiq@aef94e9~...9863192 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
…ered_vms Fix cached query for total unregistered vms (cherry picked from commit 3ebe6cc)
Gaprindashvili backport details:
|
Storage#total_unregistered_vms
andStorage#unregistered_vms
are using different queries.Query here is not same as it is here (method registered? on VM: Vm#registered? )
@kbrock can you please review? (you touched this code last time )
🎁 @ZitaNemeckova
@miq-bot add_label bug, core
@miq-bot assign @gtanzillo