Skip to content

Commit

Permalink
Fixed query that build recent records charts.
Browse files Browse the repository at this point in the history
Passing in a relation to `recent_records` to get recent vms/templates for the selected CloudTenant record

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731735
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487178
  • Loading branch information
h-kataria committed Aug 14, 2019
1 parent 6440497 commit 28427c4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions app/services/cloud_tenant_dashboard_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def get_icon(tenant)
end

def recent_images_data
recent_resources(MiqTemplate, _('Recent Images'), _('Images'))
recent_resources(MiqTemplate, _('Recent Images'), _('Images'), @record.miq_templates)
end

def recent_instances_data
recent_resources(ManageIQ::Providers::CloudManager::Vm, _('Recent Instances'), _('Instances'))
recent_resources(ManageIQ::Providers::CloudManager::Vm, _('Recent Instances'), _('Instances'), @record.vms)
end

def aggregate_status_data
Expand All @@ -75,8 +75,8 @@ def aggregate_status
}
end

def recent_resources(model, title, label)
all_resources = recent_records(model)
def recent_resources(model, title, label, relation)
all_resources = recent_records(model, relation)
config = {
:title => title,
:label => label
Expand All @@ -100,14 +100,13 @@ def recent_resources(model, title, label)
}.compact
end

def recent_records(model)
def recent_records(model, relation)
db_table = model.arel_table
to_char_args = [db_table[:created_on], Arel::Nodes::SqlLiteral.new("'YYYY-MM-DD'")]
group_by_sql = Arel::Nodes::NamedFunction.new("to_char", to_char_args)

model.where(:ems_id => @record.ext_management_system.id)
.where(db_table[:created_on].gt(30.days.ago.utc))
.group(group_by_sql.to_sql)
.count
relation.where(db_table[:created_on].gt(30.days.ago.utc))
.group(group_by_sql.to_sql)
.count
end
end

0 comments on commit 28427c4

Please sign in to comment.