Dase gem creates includes_count_of method in ActiveRecord::Relation to count associated records efficiently. See examples at https://github.com/vovayartsev/dase
Vladimir Yartsev
gem "dase", "~> 3.2.7"