Skip to content

Commit

Permalink
Cache vim_performance_state relations
Browse files Browse the repository at this point in the history
we were having trouble that the reverse relation (assoc.parent) was not being cached
Ended up deciding caching the forward and the reverse are the best
  • Loading branch information
kbrock committed Jul 3, 2023
1 parent 386f572 commit 16b542b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/metric/ci_mixin/state_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ def preload_vim_performance_state_for_ts_iso8601(conditions = {})
@states_by_ts = vim_performance_states.where(conditions).index_by { |x| x.timestamp.utc.iso8601 }
end

# Use VimPerformanceState to populate the scopes with the values from a particular point in time
# using @last_vps_ts to ensure we don't load at one time and then use at another
def vim_performance_state_association(ts, assoc)
if assoc.to_s == "miq_regions"
return respond_to?(:miq_regions) ? miq_regions : []
end

vim_performance_state_for_ts(ts).public_send(assoc)
return send(assoc) if defined?(@last_vps_ts) && @last_vps_ts == ts

@last_vps_ts = ts
public_send(assoc).reset
vim_performance_state_for_ts(ts).public_send(assoc).tap { |scope| MiqPreloader.preload(self, assoc, scope) }
end
end

0 comments on commit 16b542b

Please sign in to comment.