Skip to content

Commit

Permalink
Merge pull request #13639 from kbrock/report_both_includes
Browse files Browse the repository at this point in the history
Report both includes
  • Loading branch information
gtanzillo authored Jan 27, 2017
2 parents f2e9b74 + 5ff3b98 commit cfa975d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
22 changes: 15 additions & 7 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def table2class(table)
@table2class[table]
end

def get_include_for_find(includes, klass = nil)
def get_include_for_find
(include_as_hash || {}).deep_merge(include_for_find || {}).presence
end

def include_as_hash(includes = include, klass = nil)
if klass.nil?
klass = db_class
result = {}
Expand All @@ -98,17 +102,21 @@ def get_include_for_find(includes, klass = nil)
assoc_klass = assoc_reflection.nil? ? nil : (assoc_reflection.options[:polymorphic] ? k : assoc_reflection.klass)

if v.nil? || v["include"].blank?
result.merge!(k => {})
else
result.merge!(k => get_include_for_find(v["include"], assoc_klass)) if assoc_klass
result[k] = {}
elsif assoc_klass
result[k] = include_as_hash(v["include"], assoc_klass)
end

v["columns"].each { |c| result[k].merge!(c.to_sym => {}) if assoc_klass.virtual_attribute?(c) } if assoc_klass && assoc_klass.respond_to?(:virtual_attribute?) && v["columns"]
if assoc_klass && assoc_klass.respond_to?(:virtual_attribute?) && v["columns"]
v["columns"].each do |c|
result[k][c.to_sym] = {} if assoc_klass.virtual_attribute?(c)
end
end
end
end
elsif includes.kind_of?(Array)
result ||= {}
includes.each { |i| result.merge!(i.to_sym => {}) }
includes.each { |i| result[i.to_sym] = {} }
end

result
Expand Down Expand Up @@ -177,7 +185,7 @@ def _generate_table(options = {})
interval = db_options.present? && db_options[:interval]
custom_results_method = (db_options && db_options[:rpt_type]) ? "build_results_for_report_#{db_options[:rpt_type]}" : nil

includes = get_include_for_find(include)
includes = get_include_for_find

load_custom_attributes

Expand Down
10 changes: 4 additions & 6 deletions app/models/miq_report/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def limited_ids(limit, offset)
end
end

def get_cached_page(ids, includes, includes2, options)
data = db_class.where(:id => ids).includes(includes).includes(includes2).to_a
def get_cached_page(ids, includes, options)
data = db_class.where(:id => ids).includes(includes).to_a
targets_hash = data.index_by(&:id) if options[:targets_hash]
build_table(data, db, options)
return table, extras[:attrs_for_paging].merge(:paged_read_from_cache => true, :targets_hash => targets_hash)
Expand Down Expand Up @@ -82,12 +82,10 @@ def paged_view_search(options = {})
self.display_filter = options.delete(:display_filter_hash) if options[:display_filter_hash]
self.display_filter = options.delete(:display_filter_block) if options[:display_filter_block]

includes1 = get_include_for_find(include)
includes = MiqExpression.merge_includes(includes1, include_for_find)

includes = get_include_for_find
self.extras ||= {}
if extras[:target_ids_for_paging] && db_class.column_names.include?('id')
return get_cached_page(limited_ids(limit, offset), includes1, include_for_find, options)
return get_cached_page(limited_ids(limit, offset), includes, options)
end

order = get_order_info
Expand Down
5 changes: 0 additions & 5 deletions lib/miq_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,6 @@ def self.merge_where_clauses(*list)
end
end

def self.merge_includes(*incl_list)
return nil if incl_list.blank?
incl_list.compact.each_with_object({}) { |i, result| result.deep_merge!(i) }
end

def self.get_cols_from_expression(exp, options = {})
result = {}
if exp.kind_of?(Hash)
Expand Down

0 comments on commit cfa975d

Please sign in to comment.