Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into aws-eb-test
Browse files Browse the repository at this point in the history
  • Loading branch information
tbhi committed Jan 27, 2025
2 parents e716205 + 53200ad commit b5451b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,11 @@ def meter_attributes_to_analytics
end

def invalidate_cache_key
update_attribute(:validation_cache_key, SecureRandom.uuid)
if Flipper.enabled?(:meter_collection_cache_delete_on_invalidate)
AggregateSchoolService.new(self).invalidate_cache
else
update_attribute(:validation_cache_key, SecureRandom.uuid)
end
end

def process_data!
Expand Down
21 changes: 12 additions & 9 deletions app/services/aggregate_school_service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'dashboard'

class AggregateSchoolService
Expand Down Expand Up @@ -33,26 +35,27 @@ def in_cache_or_cache_off?
end

def self.caching_off?
! Rails.application.config.action_controller.perform_caching
!Rails.application.config.action_controller.perform_caching
end

def self.analysis_date(meter_collection, fuel_type)
return Time.zone.today unless fuel_type
fuel_type = fuel_type.to_sym
if fuel_type == :gas
case fuel_type&.to_sym
when :gas
meter_collection.aggregated_heat_meters.amr_data.end_date
elsif fuel_type == :electricity
meter_collection.aggregated_electricity_meters.amr_data.end_date
elsif fuel_type == :storage_heater
when :electricity, :storage_heater
meter_collection.aggregated_electricity_meters.amr_data.end_date
else
Time.zone.today
end
end

private
private

def cache_key
"#{@active_record_school.id}-#{@active_record_school.name.parameterize}-aggregated_meter_collection-#{@active_record_school.validation_cache_key}"
parts = [@active_record_school.id, @active_record_school.name.parameterize, 'aggregated_meter_collection']
unless Flipper.enabled?(:meter_collection_cache_delete_on_invalidate)
parts << @active_record_school.validation_cache_key
end
parts.join('-')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace :after_party do
desc 'Deployment task: flipper_meter_collection_cache_delete_on_invalidate'
task flipper_meter_collection_cache_delete_on_invalidate: :environment do
puts "Running deploy task 'flipper_meter_collection_cache_delete_on_invalidate'"

Flipper.add(:meter_collection_cache_delete_on_invalidate)

# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

0 comments on commit b5451b3

Please sign in to comment.