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

Use a single query to get count of active VMs and Hosts #19835

Merged

Conversation

agrare
Copy link
Member

@agrare agrare commented Feb 14, 2020

Instead of looping through all ExtManagementSystems and adding up the counts of vms and hosts manually we can get this count in one shot by querying for active VMs and Hosts.

Follow-up for #19830

Instead of looping through all ExtManagementSystems and adding up the
counts of vms and hosts manually we can get this count in one shot by
querying for active VMs and Hosts.
@agrare agrare force-pushed the improve_audit_managed_resources_performance branch from 17b393e to 2f83c8f Compare February 14, 2020 17:24
@@ -143,6 +143,9 @@ class Host < ApplicationRecord
virtual_total :v_total_vms, :vms
virtual_total :v_total_miq_templates, :miq_templates

scope :active, -> { where.not(:ems_id => nil) }
scope :archived, -> { where(:ems_id => nil) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are handy scopes to have, only the active scope here is used but both are generally helpful

@miq-bot
Copy link
Member

miq-bot commented Feb 14, 2020

Checked commit agrare@2f83c8f with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.20.0, and yamllint
3 files checked, 0 offenses detected
Everything looks fine. ⭐

@chessbyte
Copy link
Member

/cc @jaredm-ibm

@chessbyte
Copy link
Member

LGTM - will merge when tests are green

@chessbyte chessbyte merged commit cee35bf into ManageIQ:master Feb 14, 2020
@chessbyte chessbyte self-assigned this Feb 14, 2020
@chessbyte chessbyte added this to the Sprint 130 Ending Feb 17, 2020 milestone Feb 14, 2020
@agrare agrare deleted the improve_audit_managed_resources_performance branch February 14, 2020 17:49
simaishi pushed a commit that referenced this pull request Feb 21, 2020
…_performance

Use a single query to get count of active VMs and Hosts

(cherry picked from commit cee35bf)

https://bugzilla.redhat.com/show_bug.cgi?id=1805915
@simaishi
Copy link
Contributor

Ivanchuk backport details:

$ git log -1
commit a0a4e44be3598c5f9809d59b4a9f188d317bac0e
Author: Oleg Barenboim <chessbyte@gmail.com>
Date:   Fri Feb 14 12:47:47 2020 -0500

    Merge pull request #19835 from agrare/improve_audit_managed_resources_performance

    Use a single query to get count of active VMs and Hosts

    (cherry picked from commit cee35bfd2a2d77bde3f581737b749d38b6b8ea00)

    https://bugzilla.redhat.com/show_bug.cgi?id=1805915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants