Skip to content
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

Remove N+1 from assign_ems_create_on #656

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,22 @@ def assign_ems_created_on(vm_ids)

# Of the VMs without a VM create time, filter out the ones for which we
# already have a VM create event
events = EmsEvent
.where(
:vm_or_template_id => vms_to_update.map(&:id),
:event_type => ["VmCreatedEvent", "VmDeployedEvent"]
)
.group_by(&:vm_or_template_id)

vms_to_update = vms_to_update.reject do |v|
event = v.ems_events.find_by(:event_type => ["VmCreatedEvent", "VmDeployedEvent"])
v.update_attribute(:ems_created_on, event.timestamp) if event && v.ems_created_on != event.timestamp
event
events[v.id].tap do |event|
v.update_attribute(:ems_created_on, event.timestamp) if event && v.ems_created_on != event.timestamp
end
end
return if vms_to_update.empty?

# Of the VMs still without an VM create time, use historical events, if
# available, to determine the VM create time

vms_list = vms_to_update.collect { |v| {:id => v.id, :name => v.name, :uid_ems => v.uid_ems} }
found = find_vm_create_events(vms_list)

Expand Down