Skip to content

Commit

Permalink
Merge pull request #18822 from kbrock/turbo_for_all
Browse files Browse the repository at this point in the history
default to using inline sql views for reports
  • Loading branch information
jrafanie authored Jun 18, 2019
2 parents ac7dcc7 + 9dc5b0c commit 790ee9c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
manageiq_plugin "manageiq-schema"

# Unmodified gems
gem "activerecord-virtual_attributes", "~>1.2.0"
gem "activerecord-virtual_attributes", "~>1.3.1"
gem "activerecord-session_store", "~>1.1"
gem "acts_as_tree", "~>2.7" # acts_as_tree needs to be required so that it loads before ancestry
gem "ancestry", "~>3.0.4", :require => false
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def generate_basic_results(options = {})

## add in virtual attributes that can be calculated from sql
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank?
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
rbac_opts[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view) { true }

results, attrs = Rbac.search(rbac_opts)
results = Metric::Helper.remove_duplicate_timestamps(results)
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_report/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def paged_view_search(options = {})
)
search_options.merge!(:limit => limit, :offset => offset, :order => order) if order
search_options[:extra_cols] = va_sql_cols if va_sql_cols.present?
search_options[:use_sql_view] = true if db_options && db_options[:use_sql_view]
search_options[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view) { true }

if options[:parent]
targets = get_parent_targets(options[:parent], options[:association] || options[:parent_method])
Expand Down
9 changes: 4 additions & 5 deletions app/models/mixins/custom_attribute_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def self.add_custom_attribute(custom_attribute)
ca_sym = custom_attribute.to_sym
without_prefix = custom_attribute.sub(CUSTOM_ATTRIBUTES_PREFIX, "")
name_val, section = without_prefix.split(SECTION_SEPARATOR)
sanatized_column_alias = custom_attribute.tr('.', 'DOT').tr('/', 'BS').tr(':', 'CLN')
ca_arel = custom_attribute_arel(name_val, section, sanatized_column_alias)
ca_arel = custom_attribute_arel(name_val, section)

virtual_column(ca_sym, :type => :string, :uses => :custom_attributes, :arel => ca_arel)

define_method(ca_sym) do
return self[sanatized_column_alias] if has_attribute?(sanatized_column_alias)
return self[custom_attribute] if has_attribute?(custom_attribute)

where_args = {}
where_args[:name] = name_val
Expand All @@ -68,7 +67,7 @@ def self.add_custom_attribute(custom_attribute)
end
end

def self.custom_attribute_arel(name_val, section, column_alias)
def self.custom_attribute_arel(name_val, section)
lambda do |t|
ca_field = CustomAttribute.arel_table

Expand All @@ -81,7 +80,7 @@ def self.custom_attribute_arel(name_val, section, column_alias)
# using a `take(1)` here as well, since a limit is assumed in each.
# Without it, there can be some invalid queries if more than one result
# is returned.
ca_field.project(:value).where(field_where).take(1).as(column_alias)
t.grouping(ca_field.project(:value).where(field_where).take(1))
end
end
end
Expand Down

0 comments on commit 790ee9c

Please sign in to comment.