Skip to content

Commit

Permalink
Merge pull request ManageIQ#17195 from NickLaMuro/cache_miq_report_fo…
Browse files Browse the repository at this point in the history
…rmat_column_type_lookup

Cache MiqExpression.get_col_type in MiqReport::Formatting
(cherry picked from commit 1b18fb1)

https://bugzilla.redhat.com/show_bug.cgi?id=1565678
  • Loading branch information
gtanzillo authored and d-m-u committed Jun 6, 2018
1 parent 7484d78 commit 3f0a0b4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/models/miq_report/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ def format(col, value, options = {})

# Use default format for column stil nil
if format.nil? || format == :_default_
expression_col = col_to_expression_col(col)
dt = MiqExpression.get_col_type(expression_col)
dt = value.class.to_s.downcase.to_sym if dt.nil?
dt = dt.to_sym unless dt.nil?
format = MiqReport::Formats.default_format_details_for(expression_col, col, dt)
format = format_from_miq_expression(col, value)
else
format = format.deep_clone # Make sure we don't taint the original
end
Expand Down Expand Up @@ -244,4 +240,19 @@ def format_large_number_to_exponential_form(val, _options = {})
def format_model_name(val, _options = {})
ui_lookup(:model => val)
end

private

def format_from_miq_expression(col, value)
@miq_exp_dt_map ||= {}
expression_col = col_to_expression_col(col)

unless @miq_exp_dt_map.key?(col)
@miq_exp_dt_map[col] = MiqExpression.get_col_type(expression_col)
end
dt = @miq_exp_dt_map[col]
dt = value.class.to_s.downcase if dt.nil?
dt = dt.to_sym unless dt.nil?
MiqReport::Formats.default_format_details_for(expression_col, col, dt)
end
end

0 comments on commit 3f0a0b4

Please sign in to comment.