Skip to content

Instantly share code, notes, and snippets.

@handshake-engineering-blog
Created June 23, 2021 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handshake-engineering-blog/31f8d80dfa46993d589c374710bdede1 to your computer and use it in GitHub Desktop.
Save handshake-engineering-blog/31f8d80dfa46993d589c374710bdede1 to your computer and use it in GitHub Desktop.
17_3
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