-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CAPT 983/slow loading payroll #3250
Conversation
7253886
to
479469c
Compare
257cbc7
to
86ac927
Compare
86ac927
to
7958a55
Compare
@@ -33,7 +33,7 @@ def create | |||
|
|||
# NOTE: Optimisation - preload payments, claims and eligibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# NOTE: Optimisation - preload payments, claims and eligibility |
app/models/base_policy.rb
Outdated
@@ -58,4 +58,12 @@ def further_education_payments? | |||
def auto_check_student_loan_plan_task? | |||
false | |||
end | |||
|
|||
def award_amount_column | |||
if to_s == "StudentLoans" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the StudentLoans
model should override this method instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's nicer, have fixed 👍
Rather than looping through all payments each time we can just loop through the payments for the provided policy.
Makes understanding what's going on easier
@Items doesn't need to be an instance variable
Doesn't speed things up as we're hitting the AR cache but cleans up the noise in the logs
We hit this line items method multiple times with the same policy, cache the results.
On my test data set this takes the page load from 7s to ~500ms
Refactors the CTE to build a generic eligibilities table we can join to. Now when we add a new policy the payroll query should automatically pick it up. Ideally we'd rename the "student_loan_repayment_amount" column in the DB but that's quite involved, so for the time being we define an 'award_amount_column' column on the policy which returns the name of the DB column we need to check to get the award amount.
Adds a new scope to claim `with_award_amount` allowing for querying claims in the db by their award amount.
7958a55
to
24dcf92
Compare
Speed up payroll run queries.
In order to shift more of the payroll query work to the database we need to be able to join to the various eligibility tables. To make this trickier the column name for
award_amount
is different on some policy's eligibilities (ie student_loans). This PR introduces a new claim scopewith_award_amount
that handles joining claims to the eligibilities tables and picking the correct column for the award amount.Of note this PR makes the following assumptions (which are also made on master but it's worth calling them out)
Benchmarks
Hitting the payroll index page
Master
:view_runtime=>6573.04, :db_runtime=>2113.22, :allocations=>13379102
This branch
:view_runtime=>248.16, :db_runtime=>517.15, :allocations=>481363
Payroll show for Nov 23, with 3k claims
Master
:view_runtime=>4479.93, :db_runtime=>325.29, :allocations=>10520859
This branch
:view_runtime=>189.02, :db_runtime=>187.99, :allocations=>311803