Skip to content

Commit

Permalink
Memoize the block_sync_enabled? call for FacilitiesController
Browse files Browse the repository at this point in the history
  • Loading branch information
kitallis committed Dec 17, 2020
1 parent 7cf2e40 commit e424312
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/api/v3/facilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ 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
# Ignore nil values
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
Expand Down

0 comments on commit e424312

Please sign in to comment.