I've been trying to track down a performance problem (one of many) within our application that sucks 200 seconds (or more) when doing something really simple. The design of the model is this:
class Study
has_many :requests
has_many :projects, :through => :requests, :uniq => true
end
Essentially we have a study that can request some work to be done in our laboratories and that work is done as part of a project, which is responsible for paying for it later. So a study can be related to many projects through the work it has requested.
This all works fine until you want to do eager loading of the projects association, specifically within a query for multiple studies. For example, the killer query comes from: