These are chat archives for ManageIQ/manageiq/performance

16th
Nov 2016
Keenan Brock
@kbrock
Nov 16 2016 21:01

ugh

module ComplianceMixin
  extend ActiveSupport::Concern

  included do
    has_many :compliances, :as => :resource, :dependent => :destroy

    virtual_has_one :last_compliance, :class_name => "Compliance"

    virtual_column  :last_compliance_status,    :type => :boolean,  :uses => :last_compliance
    virtual_column  :last_compliance_timestamp, :type => :datetime, :uses => :last_compliance
  end

I hate this pattern of has_one :last_*
forces an n+1

we have this in quite a few places, not just this module per say. (wanted to be concrete in my whining)
Jason Frey
@Fryguy
Nov 16 2016 21:02
Now we know better :)
Keenan Brock
@kbrock
Nov 16 2016 21:02
lol
no idea how to fix this though :(
maybe introduce a virtual_last_one helper or something
finding something that is AR relation friendly is tricky. (If I remember correctly from my last stack overflow fixes)

@Fryguy right_size...

  def cpu_usagemhz_rate_average_max_over_time_period
    perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS)
    perfs.to_a.collect(&:cpu_usagemhz_rate_average).compact.max
  end

any wisdom you have for me before I dive too deep?