acts_as_follower icon indicating copy to clipboard operation
acts_as_follower copied to clipboard

Avoid n+1 queries

Open lsarni opened this issue 7 years ago • 1 comments

Is there a way to avoid n+1 queries?

I have a class Company:

class Company < ActiveRecord::Base
   acts_as_followable  
end

And I make a query to get a certain type of companies, but I want to get the followers of each one of those and I end up with n+1 queries:

SELECT COUNT(*) FROM "follows" WHERE "follows"."followable_id" = $1 AND "follows"."followable_type" = $2 AND "follows"."blocked" = $3 [["followable_id", 419], ["followable_type", "Company"], ["blocked", "f"]]

lsarni avatar Oct 16 '17 19:10 lsarni

Anyone created a fork with optimized queries for this issue yet??

RailsCod3rFuture avatar Feb 01 '19 18:02 RailsCod3rFuture