-
Notifications
You must be signed in to change notification settings - Fork 21
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
Speed alert emails #7318
base: main
Are you sure you want to change the base?
Speed alert emails #7318
Conversation
70787d1
to
120c6ec
Compare
07333e2
to
4a7fd07
Compare
config.before(:each, disable_expensive_jobs: true) do | ||
allow(DisableExpensiveJobs).to receive(:enabled?).and_return(true) | ||
end |
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.
Very nice 👏
@@ -1,19 +1,20 @@ | |||
class AlertEmail::Base < ApplicationJob | |||
MAXIMUM_RESULTS_PER_RUN = 500 |
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.
Is this still needed? I only see this removed call
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.
It was - I've put the usage back.
app/jobs/alert_email/base.rb
Outdated
subscriptions.find_each.reject { |sub| already_run_ids.include?(sub.id) }.each do |subscription| | ||
vacancies = subscription.vacancies_matching default_scope |
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.
This seems to be looping twice over the subscriptions batch: once for the reject, and a second for finding/alerting.
We could avoid the first loop:
subscriptions.find_each.reject { |sub| already_run_ids.include?(sub.id) }.each do |subscription| | |
vacancies = subscription.vacancies_matching default_scope | |
subscriptions.find_each.each do |subscription| | |
next if already_run_ids.include?(subscription.id) | |
vacancies = subscription.vacancies_matching default_scope |
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.
don't think it does. find_each is a lazy ierator IIRC so this pattern (which is pretty standard) works efficiently.
YAML.unsafe_load_file(Rails.root.join("spec/fixtures/polygons.yml")).map(&:attributes).each { |s| LocationPolygon.create!(s) } | ||
YAML.unsafe_load_file(Rails.root.join("spec/fixtures/liverpool_schools.yml")).map(&:attributes).each { |s| School.create!(s) } | ||
create(:vacancy, :published_slugged, slug: "liv", contact_number: "0", organisations: [liverpool_school], job_roles: %w[headteacher], visa_sponsorship_available: false, ect_status: :ect_unsuitable, subjects: %w[German], phases: %w[secondary], working_patterns: %w[full_time]) |
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.
very nice test setup for a complex case! 👏
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.
Great work! Left a few comments for possible optimizations, but nothing blocking!
62d99d2
to
7055934
Compare
Review app deployed to https://teaching-vacancies-review-pr-7318.test.teacherservices.cloud on AKS |
Trello card URL
https://trello.com/c/w1KM928B/1414-refactor-daily-weeklyalerts-job-for-a-high-volume-of-subscriptions
Changes in this PR:
Currently each (of 100k) subscriptions triggers an SQL query for the same (small) subset of recent vacancies. This change turns that on its head - if there are no keyword or location filters, the filtering is now all done in memory on the 'recent' subset (around 2000 for the 'weekly' email).
Screenshots of UI changes:
Before
After
Next steps:
Terraform deployment required?
New development configuration to be shared?