From 0b18ad0130b0d247f59d780cdc686d3a83ea2aef Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Thu, 17 Dec 2020 15:54:34 +0530 Subject: [PATCH] Memoize the block_sync_enabled? call for FacilitiesController --- app/controllers/api/v3/facilities_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v3/facilities_controller.rb b/app/controllers/api/v3/facilities_controller.rb index 1225d1c4c0..64aa9230da 100644 --- a/app/controllers/api/v3/facilities_controller.rb +++ b/app/controllers/api/v3/facilities_controller.rb @@ -52,8 +52,14 @@ def records_to_sync private + # Memoize this call here so that we don't end up making thousands of calls to check user for each facility + def block_level_sync? + @is_block_level_sync_enabled = current_user&.block_level_sync? if @is_block_level_sync_enabled.nil? + @is_block_level_sync_enabled + end + def sync_region_id(facility) - if current_user&.block_level_sync? + if block_level_sync? facility.block_region_id else facility.facility_group_id