Skip to content

Commit

Permalink
Fix regression with POA missing cache (#14305)
Browse files Browse the repository at this point in the history
### Description

Fixes regression introduced in #13922 with the advent of the BgsPowerOfAttorney AR model.

We were skipping our local db cache and always making BGS calls, which slowed the job down to take hours instead of minutes.
  • Loading branch information
pkarman authored May 15, 2020
1 parent 7270430 commit f15e162
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ detectors:
- Seeds::Users#create_aod_user_and_tasks
- SyncReviewsJob
- TaskTimerJob
- UpdateCachedAppealsAttributesJob#assignees_for_vacols_id
- UpdateCachedAppealsAttributesJob
- UserReporter#report_user_related_records
- User#current_case_assignments_with_views
- User#appeal_has_task_assigned_to_user?
Expand Down Expand Up @@ -143,6 +143,7 @@ detectors:
- RequestIssue
- BulkTaskReassignment
- Task
- UpdateCachedAppealsAttributesJob
TooManyConstants:
exclude:
- Fakes::BGSServicePOA
Expand Down
12 changes: 10 additions & 2 deletions app/jobs/update_cached_appeals_attributes_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def cache_legacy_appeal_postgres_data(legacy_appeals)
values_to_cache = legacy_appeals.map do |appeal|
regional_office = RegionalOffice::CITIES[appeal.closest_regional_office]
# bypass PowerOfAttorney model completely and always prefer BGS cache
bgs_poa = BgsPowerOfAttorney.new(file_number: appeal.veteran_file_number)
bgs_poa = fetch_bgs_power_of_attorney_by_file_number(appeal.veteran_file_number)
{
vacols_id: appeal.vacols_id,
appeal_id: appeal.id,
appeal_type: LegacyAppeal.name,
closest_regional_office_city: regional_office ? regional_office[:city] : COPY::UNKNOWN_REGIONAL_OFFICE,
closest_regional_office_key: regional_office ? appeal.closest_regional_office : COPY::UNKNOWN_REGIONAL_OFFICE,
docket_type: appeal.docket_name, # "legacy"
power_of_attorney_name: bgs_poa.representative_name || appeal.representative_name,
power_of_attorney_name: (bgs_poa&.representative_name || appeal.representative_name),
suggested_hearing_location: appeal.suggested_hearing_location&.formatted_location
}
end
Expand All @@ -128,6 +128,14 @@ def cache_legacy_appeal_postgres_data(legacy_appeals)
end
# rubocop:enable Metrics/MethodLength

def fetch_bgs_power_of_attorney_by_file_number(file_number)
return if file_number.blank?

BgsPowerOfAttorney.find_or_create_by_file_number(file_number)
rescue ActiveRecord::RecordInvalid # not found at BGS
BgsPowerOfAttorney.new(file_number: file_number)
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def cache_legacy_appeal_vacols_data(all_vacols_ids)
Expand Down

0 comments on commit f15e162

Please sign in to comment.