diff --git a/app/services/reports/region_cache_warmer.rb b/app/services/reports/region_cache_warmer.rb index 362f6b34a6..95ed0ed929 100644 --- a/app/services/reports/region_cache_warmer.rb +++ b/app/services/reports/region_cache_warmer.rb @@ -4,7 +4,7 @@ def self.call new.call end - BATCH_SIZE = 100 + BATCH_SIZE = 1000 def initialize(period: RegionService.default_period) @period = period @@ -29,6 +29,11 @@ def call cache_facility_groups end + notify "starting block caching" + Statsd.instance.time("region_cache_warmer.blocks") do + cache_blocks + end + notify "starting facility caching" Statsd.instance.time("region_cache_warmer.facilities") do cache_facilities @@ -58,6 +63,13 @@ def cache_facility_groups end end + def cache_blocks + Region.block_regions.find_each(batch_size: BATCH_SIZE).each do |region| + RegionService.call(region: region, period: period) + Statsd.instance.increment("region_cache_warmer.blocks.cache") + end + end + def cache_facilities Facility.find_each(batch_size: BATCH_SIZE).each do |region| RegionService.call(region: region, period: period) diff --git a/config/initializers/active_record_query_trace.rb b/config/initializers/active_record_query_trace.rb index df75e6aa2d..033537bd68 100644 --- a/config/initializers/active_record_query_trace.rb +++ b/config/initializers/active_record_query_trace.rb @@ -1,6 +1,6 @@ if Rails.env.development? # See https://github.com/brunofacca/active-record-query-trace for docs + ActiveRecordQueryTrace.enabled = false ActiveRecordQueryTrace.level = :app - ActiveRecordQueryTrace.enabled = true ActiveRecordQueryTrace.lines = 15 end diff --git a/spec/services/reports/region_cache_warmer_spec.rb b/spec/services/reports/region_cache_warmer_spec.rb index de52473fdb..0f921ca308 100644 --- a/spec/services/reports/region_cache_warmer_spec.rb +++ b/spec/services/reports/region_cache_warmer_spec.rb @@ -37,8 +37,9 @@ def refresh_views end it "warms the cache for all regions" do - facilities = FactoryBot.create_list(:facility, 5, facility_group: facility_group_1) + facilities = FactoryBot.create_list(:facility, 5, block: "Block 1", facility_group: facility_group_1) + expect(Reports::RegionService).to receive(:call).with(hash_including(region: instance_of(Region))).exactly(1).times expect(Reports::RegionService).to receive(:call).with(hash_including(region: instance_of(FacilityGroup))).exactly(1).times expect(Reports::RegionService).to receive(:call).with(hash_including(region: instance_of(Facility))).exactly(5).times Reports::RegionCacheWarmer.call