diff --git a/app/models/chargeback/rates_cache.rb b/app/models/chargeback/rates_cache.rb index 7424a8e314f..abc6846ba9b 100644 --- a/app/models/chargeback/rates_cache.rb +++ b/app/models/chargeback/rates_cache.rb @@ -3,22 +3,9 @@ class RatesCache def get(perf) @rates ||= {} @rates[perf.hash_features_affecting_rate] ||= - begin - prefix = tag_prefix(perf) - ChargebackRate.get_assigned_for_target(perf.resource, - :tag_list => perf.tag_list_reconstruct.map! { |t| prefix + t }, - :parents => perf.parents_determining_rate) - end - end - - private - - def tag_prefix(perf) - case perf.resource_type - when Container.name then 'container_image' - when VmOrTemplate.name then 'vm' - when ContainerProject.name then 'container_project' - end + ChargebackRate.get_assigned_for_target(perf.resource, + :tag_list => perf.tag_list_with_prefix, + :parents => perf.parents_determining_rate) end end end diff --git a/app/models/metric/chargeback_helper.rb b/app/models/metric/chargeback_helper.rb index fb25e9a2055..2b9c6a5d029 100644 --- a/app/models/metric/chargeback_helper.rb +++ b/app/models/metric/chargeback_helper.rb @@ -1,4 +1,6 @@ module Metric::ChargebackHelper + TAG_MANAGED_PREFIX = "/tag/managed/".freeze + def hash_features_affecting_rate tags = tag_names.split('|').reject { |n| n.starts_with?('folder_path_') }.sort.join('|') keys = [tags] + resource_parents.map(&:id) @@ -6,14 +8,23 @@ def hash_features_affecting_rate keys.join('_') end - def tag_list_reconstruct - tag_list = tag_names.split("|").inject([]) { |arr, t| arr << "/tag/managed/#{t}" } + def tag_prefix + klass_prefix = case resource_type + when Container.name then 'container_image' + when VmOrTemplate.name then 'vm' + when ContainerProject.name then 'container_project' + end + + klass_prefix + TAG_MANAGED_PREFIX + end - if resource_type == Container.name + def tag_list_with_prefix + if resource.kind_of?(Container) state = resource.vim_performance_state_for_ts(timestamp.to_s) - tag_list += state.image_tag_names.split("|").inject([]) { |arr, t| arr << "/tag/managed/#{t}" } if state.present? + image_tag_name = "#{state.image_tag_names}|" if state end - tag_list + + "#{image_tag_name}#{tag_names}".split("|").reject(&:empty?).map { |x| "#{tag_prefix}#{x}" } end def resource_parents