remove multiple responsibility in controller

Using dedicated CostQuery::Cache for this
pull/6827/head
Jens Ulferts 9 years ago
parent 383028a85d
commit 01b5839cd2
  1. 21
      app/controllers/cost_reports_controller.rb
  2. 2
      spec/models/cost_query/filter_spec.rb
  3. 2
      spec/models/cost_query/group_by_spec.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
##

@ -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

@ -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

Loading…
Cancel
Save