-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove N+1 queries #272
Comments
It must be related to the way we are using polymorphic associations:
In the controller functions we are calling the impressions on the impressionable model instance, which I expect would take into consideration the
I'm not sure if this is an ActiveRecord limitation or just the way we are using it. I'll have to do some more research. But you may be able to do this manually in your code to avoid the N+1 by using the
Can you try something like that and let me know if you are still seeing the N+1 calls to the impressions table? Also, when you were using the |
Good idea @johnmcaliley. I iterated on the It also recognizes new impressions and renders them (tested in another browser with a cleared cache and cookies).
|
For example:
I'm using the
impressionist
method directly, taking all of theJobs
on the page and logging an impression. The problem is because I'm only recording unique impressions, for records that already have animpression
, these additional calls are redundant. I tried to use@jobs.includes(:impressions).each
to preload the associated data hoping Rails was smart enough to figure out which records existed, but Rails still outputs numerousImpression Exists
queries.The text was updated successfully, but these errors were encountered: