These are chat archives for ManageIQ/manageiq/performance

Nov 2016
Keenan Brock
Nov 16 2016 21:01


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

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
Nov 16 2016 21:02
Now we know better :)
Keenan Brock
Nov 16 2016 21:02
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 =>, :days => Metric::LongTermAverages::AVG_DAYS)

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