Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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