Skip to content

Commit

Permalink
[MiqReport::Generator] Avoid polymorphic to Rbac
Browse files Browse the repository at this point in the history
This changes what is passed to Rbac from MiqReport::Generator to avoid
passing keys for includes/references that are polymorphic in nature.

This means that there might be a bit of a performance degradation on
some reports, but for now stability is being favored over performance.

Follow up:  For the keys that are skipped, a MiqPreload should probably
be called to avoid N+1 calls, but unsure where the best for this would
be.
  • Loading branch information
NickLaMuro committed Feb 4, 2020
1 parent c40183b commit 6f23bdc
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ def get_include
include_as_hash(include.presence || invent_report_includes)
end

def polymorphic_includes
@polymorphic_includes ||= begin
polymorphic_rels = []
top_level_rels = []
top_level_rels += Array(get_include.try(:keys))
top_level_rels += Array(get_include_for_find.try(:keys))

top_level_rels.uniq.each do |assoc|
reflection = db_klass.reflect_on_association(assoc)
polymorphic_rels << assoc if reflection && reflection.polymorphic?
end

polymorphic_rels
end
end

def get_include_for_find_rbac
polymorphic_includes.each_with_object(get_include_for_find.dup) do |key, includes|
includes.delete(key)
end
end

def get_include_rbac
polymorphic_includes.each_with_object(get_include.dup) do |key, includes|
includes.delete(key)
end
end

def invent_includes
include_as_hash(invent_report_includes)
end
Expand Down Expand Up @@ -312,8 +340,8 @@ def generate_basic_results(options = {})
rbac_opts = options.merge(
:targets => targets,
:filter => conditions,
:include_for_find => get_include_for_find,
:references => get_include,
:include_for_find => get_include_for_find_rbac,
:references => get_include_rbac,
:where_clause => where_clause,
:skip_counts => true
)
Expand Down

0 comments on commit 6f23bdc

Please sign in to comment.