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

Report both includes #13639

Merged
merged 3 commits into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
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
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 ||= {}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is basically the whole PR:

# before
includes = MiqExpression.merge_includes(get_include_for_find, include_for_find)
# after
includes = get_include_for_find

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