diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index 22d51177a4..0984ccae70 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -46,29 +46,12 @@ class CostReportsController < ApplicationController helper_method :private_queries attr_accessor :cost_types, :unit_id, :cost_type - cattr_accessor :custom_fields_updated_on, :custom_fields_id_sum # Checks if custom fields have been updated, added or removed since we # last saw them, to rebuild the filters and group bys. # Called once per request. - def check_cache(force_update = false) - custom_fields_updated_on = WorkPackageCustomField.maximum(:updated_at) - custom_fields_id_sum = WorkPackageCustomField.sum(:id) + WorkPackageCustomField.count - - if force_update or (custom_fields_updated_on && custom_fields_id_sum) - if force_update or ( - self.class.custom_fields_updated_on != custom_fields_updated_on || - self.class.custom_fields_id_sum != custom_fields_id_sum) - - self.class.custom_fields_updated_on = custom_fields_updated_on - self.class.custom_fields_id_sum = custom_fields_id_sum - - CostQuery::Filter.reset! - CostQuery::Filter::CustomFieldEntries.reset! - CostQuery::GroupBy.reset! - CostQuery::GroupBy::CustomFieldEntries.reset! - end - end + def check_cache + CostQuery::Cache.check end ## diff --git a/spec/models/cost_query/filter_spec.rb b/spec/models/cost_query/filter_spec.rb index c0ed74068a..9103966fdb 100644 --- a/spec/models/cost_query/filter_spec.rb +++ b/spec/models/cost_query/filter_spec.rb @@ -329,7 +329,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end def clear_cache - CostReportsController.new.check_cache(true) + CostQuery::Cache.reset! CostQuery::Filter::CustomFieldEntries.all end diff --git a/spec/models/cost_query/group_by_spec.rb b/spec/models/cost_query/group_by_spec.rb index 2e4a8de424..31cb8e3cdf 100644 --- a/spec/models/cost_query/group_by_spec.rb +++ b/spec/models/cost_query/group_by_spec.rb @@ -223,7 +223,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end def check_cache - CostReportsController.new.check_cache + CostQuery::Cache.reset! CostQuery::GroupBy::CustomFieldEntries.all end