-
-
Save handshake-engineering-blog/31f8d80dfa46993d589c374710bdede1 to your computer and use it in GitHub Desktop.
17_3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def job_reviews_count | |
SizeBatchLoader.for(object[:id]).batch do |employer_ids, loader| | |
# Query for all of the JobReviews for the employers we need, and only select the one column that will be used | |
job_reviews = JobReview.select(:employer_id).where(employer_id: employer_ids) | |
employer_ids.each do |employer_id| | |
# Filter the full set of results for each employer. This is what will be passed to the sync method in the new BatchLoader we created. | |
loader.call(employer_id, job_reviews.filter { |job_review| job_review.employer_id == employer_id }) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment