@ -31,7 +31,7 @@ module PrefillFieldsHelper
begin
begin
cached_result = Rails . cache . read ( cache_key )
cached_result = Rails . cache . read ( cache_key )
return cached_result if cached_result
return cached_result if cached_result
rescue StandardError = > e
rescue StandardError
# Continue with normal processing if cache read fails
# Continue with normal processing if cache read fails
end
end
@ -49,14 +49,13 @@ module PrefillFieldsHelper
cache_result ( cache_key , valid_fields , ATS_FIELDS_CACHE_TTL )
cache_result ( cache_key , valid_fields , ATS_FIELDS_CACHE_TTL )
valid_fields
valid_fields
rescue StandardError = > e
rescue StandardError
# Cache empty result for failed parsing to avoid repeated failures
# Cache empty result for failed parsing to avoid repeated failures
cache_result ( cache_key , [ ] , 5 . minutes )
cache_result ( cache_key , [ ] , 5 . minutes )
[ ]
[ ]
end
end
end
end
# Merges ATS prefill values with existing submitter values
# Merges ATS prefill values with existing submitter values
#
#
# This method combines ATS-provided prefill values with values already entered by submitters.
# This method combines ATS-provided prefill values with values already entered by submitters.
@ -93,9 +92,7 @@ module PrefillFieldsHelper
next if matching_field_uuid . nil?
next if matching_field_uuid . nil?
# Only set if submitter hasn't already filled this field
# Only set if submitter hasn't already filled this field
if submitter_values [ matching_field_uuid ] . blank?
submitter_values [ matching_field_uuid ] = value if submitter_values [ matching_field_uuid ] . blank?
submitter_values [ matching_field_uuid ] = value
end
end
end
submitter_values
submitter_values
@ -129,7 +126,7 @@ module PrefillFieldsHelper
def cache_result ( cache_key , value , ttl )
def cache_result ( cache_key , value , ttl )
Rails . cache . write ( cache_key , value , expires_in : ttl )
Rails . cache . write ( cache_key , value , expires_in : ttl )
rescue StandardError = > e
rescue StandardError
# Continue execution even if caching fails
# Continue execution even if caching fails
end
end
@ -164,7 +161,7 @@ module PrefillFieldsHelper
begin
begin
cached_lookup = Rails . cache . read ( cache_key )
cached_lookup = Rails . cache . read ( cache_key )
return cached_lookup if cached_lookup
return cached_lookup if cached_lookup
rescue StandardError = > e
rescue StandardError
# Continue with normal processing if cache read fails
# Continue with normal processing if cache read fails
end
end
@ -173,15 +170,13 @@ module PrefillFieldsHelper
prefill_name = field [ 'prefill' ]
prefill_name = field [ 'prefill' ]
field_uuid = field [ 'uuid' ]
field_uuid = field [ 'uuid' ]
if prefill_name . present? && field_uuid . present?
hash [ prefill_name ] = field_uuid if prefill_name . present? && field_uuid . present?
hash [ prefill_name ] = field_uuid
end
end
end
# Cache the lookup with error handling
# Cache the lookup with error handling
begin
begin
Rails . cache . write ( cache_key , lookup , expires_in : FIELD_LOOKUP_CACHE_TTL )
Rails . cache . write ( cache_key , lookup , expires_in : FIELD_LOOKUP_CACHE_TTL )
rescue StandardError = > e
rescue StandardError
# Continue execution even if caching fails
# Continue execution even if caching fails
end
end
@ -208,8 +203,6 @@ module PrefillFieldsHelper
field_lookup [ field_name ]
field_lookup [ field_name ]
end
end
private
# Generates cache key for field lookup optimization
# Generates cache key for field lookup optimization
def field_lookup_cache_key ( template_fields )
def field_lookup_cache_key ( template_fields )
# Create a hash based on the structure of template fields for caching
# Create a hash based on the structure of template fields for caching
@ -217,5 +210,4 @@ module PrefillFieldsHelper
hash = Digest :: SHA256 . hexdigest ( fields_signature )
hash = Digest :: SHA256 . hexdigest ( fields_signature )
" field_lookup: #{ hash } "
" field_lookup: #{ hash } "
end
end
end
end