-
Notifications
You must be signed in to change notification settings - Fork 527
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
Draper forces DB queries on decorated model's associations #646
Comments
👍 We're pretty aggressive with our eager loading so this is causing a pretty big hit to perf on certain views. Decorating the individual elements rather than the collection avoids this issue. |
Has this been fixed? I'm experiencing the same issue as @dimroc on draper 2.1.0. I needed to use the same workaround, to avoid the problem:
|
I just noticed this as well. @jcasimir sorry for the 2 year old question, but do you remember why this was closed? |
Given that there isn't a commit or PR linked to this ticket, I suspect it's still an issue. |
I was able to reproduce this behavior and I fixed it by using class UserDecorator < Draper::Decorator
delegate_all
decorates_associated :posts
end
class PostDecorator < Draper::Decorator
delegate_all
decorates_associated :comments
end Were the rest of you experiencing this issue also overriding the association method in the decorator? If so, you should be able to change it to the code above. If there is another scenario that is causing this, please let me. If you could provide an example app, that would be even better. |
I tried this in two projects with version draper 3.0.0.pre1.
In the first application (straight Rails and ActiveRecord) I got eager
loading to work even without the `decorates_associated`. Everything was
great there, and I don't remember that being the case.
In my second application I had mixed results. I also got eager loading
working even without the `decorates_associated` but I also had it fail with
it. This code base has many requests intertwined with ElasticSearch, and
eager loading across two data stores doesn't make for a clean example.
Perhaps someone else can come up with a failing scenario.
For me, it looks like it's been resolved.
…On Wed, Apr 5, 2017 at 11:11 PM Cliff Braton ***@***.***> wrote:
I was able to reproduce this behavior and I fixed it by using
decorates_associated instead of overriding the method:
class UserDecorator < Draper::Decorator
delegate_all
decorates_associated :postsend
class PostDecorator < Draper::Decorator
delegate_all
decorates_associated :commentsend
Were the rest of you experiencing this issue also overriding the
association method in the decorator? If so, you should be able to change it
to the code above. If there is another scenario that is causing this,
please let me. If you could provide an example app, that would be even
better.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#646 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAmw8bXwdugS5pHX73BA_LdgUEOu5Bfoks5rtFfYgaJpZM4DKmCq>
.
|
I couldn't find the part of our app that I was seeing this in now. It appeared to be working where I thought the problem was now. It was a low traffic part so I guess I didn't bother to document it anywhere. I'd call it resolved for now. I'll make sure to get more details if/when I see it again. |
Okay, I'm going to close this then. Thanks for the responses. |
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
Assume:
User has_many posts
Post has_many comments
When fetching users from DB with preloading of posts and comments:
The AR properly preloads users, posts and comments (3 queries) but decorated users' collection forces new DB queries when rendering view.
It seems that objects from decorated collection ignore the fact that associations are preloaded by AR and fore new DB query for each one. This results with a performance drop.
RABL:
User partial
Post partial
Comment partial
User decorator
Post decorator
The text was updated successfully, but these errors were encountered: