Skip to content

Commit

Permalink
Calvin/appeals 52551 (#22293)
Browse files Browse the repository at this point in the history
* age_of_n_oldest_priority_appeals_available_to_judge time out changes

* fixed timeout issue for distribute_priority_appeals

* fixed lint errors
  • Loading branch information
calvincostaBAH authored Jul 25, 2024
1 parent 6a69613 commit 638a318
Showing 1 changed file with 71 additions and 27 deletions.
98 changes: 71 additions & 27 deletions app/models/vacols/case_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,43 @@ def self.age_of_n_oldest_genpop_priority_appeals(num)
appeals.map { |appeal| appeal["bfdloout"] }
end

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num)
priority_cdl_query = generate_priority_case_distribution_lever_query
priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query
conn = connection

query = <<-SQL
#{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19}
where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null or #{priority_cdl_query} or #{priority_cdl_aod_query})
SQL
# {Query is broken up differently for when both levers are infinite due to a timeout caused by the large query}
query = if CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite &&
CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.infinite
<<-SQL
#{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19}
where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null
or ((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity})
and (#{priority_cdl_query} or #{priority_cdl_aod_query})))
SQL
else
<<-SQL
#{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19}
where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null or #{priority_cdl_query} or #{priority_cdl_aod_query})
SQL
end

fmtd_query = sanitize_sql_array([
query,
judge.vacols_attorney_id,
judge.vacols_attorney_id,
judge.vacols_attorney_id
])
fmtd_query = if CaseDistributionLever.cavc_aod_affinity_days != Constants.ACD_LEVERS.infinite &&
CaseDistributionLever.cavc_affinity_days != Constants.ACD_LEVERS.infinite
sanitize_sql_array([
query,
judge.vacols_attorney_id,
judge.vacols_attorney_id,
judge.vacols_attorney_id
])
else
sanitize_sql_array([
query,
judge.vacols_attorney_id,
judge.vacols_attorney_id
])
end

appeals = conn.exec_query(fmtd_query).to_a

Expand All @@ -371,7 +392,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num)

appeals.map { |appeal| appeal["bfd19"] }
end
# rubocop:enable
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize

def self.age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num)
conn = connection
Expand Down Expand Up @@ -542,29 +563,54 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo
distribute_appeals(fmtd_query, judge, limit, dry_run)
end

# rubocop:disable Metrics/AbcSize
def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false)
priority_cdl_query = generate_priority_case_distribution_lever_query
priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query
query = if use_by_docket_date?

# {Query is broken up differently for when both levers are infinite due to a timeout caused by the large query}
query = if use_by_docket_date? && CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite &&
CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.infinite
<<-SQL
#{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19}
where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) or #{priority_cdl_query} or #{priority_cdl_aod_query})
where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?)
or (VLJ is null and 1 = ?)
or ((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity})
and (#{priority_cdl_query} or #{priority_cdl_aod_query})))
SQL
elsif use_by_docket_date?
<<-SQL
#{SELECT_PRIORITY_APPEALS}
where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?)
or (VLJ is null and 1 = ?) or #{priority_cdl_query} or #{priority_cdl_aod_query})
SQL
else
<<-SQL
#{SELECT_PRIORITY_APPEALS}
where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) or #{priority_cdl_query} or #{priority_cdl_aod_query})
where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?)
or (VLJ is null and 1 = ?) or #{priority_cdl_query} or #{priority_cdl_aod_query})
SQL
end

fmtd_query = sanitize_sql_array([
query,
judge.vacols_attorney_id,
(genpop == "any" || genpop == "not_genpop") ? 1 : 0,
(genpop == "any" || genpop == "only_genpop") ? 1 : 0,
judge.vacols_attorney_id,
judge.vacols_attorney_id
])
fmtd_query = if CaseDistributionLever.cavc_aod_affinity_days != Constants.ACD_LEVERS.infinite &&
CaseDistributionLever.cavc_affinity_days != Constants.ACD_LEVERS.infinite
sanitize_sql_array([
query,
judge.vacols_attorney_id,
(genpop == "any" || genpop == "not_genpop") ? 1 : 0,
(genpop == "any" || genpop == "only_genpop") ? 1 : 0,
judge.vacols_attorney_id,
judge.vacols_attorney_id
])
else
sanitize_sql_array([
query,
judge.vacols_attorney_id,
(genpop == "any" || genpop == "not_genpop") ? 1 : 0,
(genpop == "any" || genpop == "only_genpop") ? 1 : 0,
judge.vacols_attorney_id
])
end

distribute_appeals(fmtd_query, judge, limit, dry_run)
end
Expand Down Expand Up @@ -613,8 +659,7 @@ def self.generate_priority_case_distribution_lever_query
"((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is null or PREV_DECIDING_JUDGE is not null)
and AOD = '0' and BFAC = '7')"
elsif CaseDistributionLever.cavc_affinity_days == "infinite"
"((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or
#{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '0' and BFAC = '7')"
"(AOD = '0' and BFAC = '7')"
else
"VLJ = ?"
end
Expand All @@ -626,8 +671,7 @@ def self.generate_priority_case_distribution_lever_aod_query
"((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is null or PREV_DECIDING_JUDGE is not null)
and AOD = '1' and BFAC = '7' )"
elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite
"((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or
#{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )"
"(AOD = '1' and BFAC = '7')"
else
"VLJ = ?"
end
Expand All @@ -637,7 +681,7 @@ def self.use_by_docket_date?
FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user])
end

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def self.cavc_affinity_filter(appeals, judge)
appeals.reject! do |appeal|
next if tied_to_or_not_cavc?(appeal, judge)
Expand Down

0 comments on commit 638a318

Please sign in to comment.