Eagerloading before export to avoid N+1 Issues #8
Replies: 5 comments 8 replies
-
This may be the same as laravel/nova-issues#6191 but that got converted to a discussion then never had any further input. |
Beta Was this translation helpful? Give feedback.
-
I've actually taken a swing at adding this myself but I'm getitng nowhere fast.
This replacement is giving exactly the same squery breakdown (N+2) so clearly I'm getting something wrong. |
Beta Was this translation helpful? Give feedback.
-
@philsturgeon would it be detrimental to always have these relationships loaded? If not, you could use |
Beta Was this translation helpful? Give feedback.
-
@edgrosvenor I wondered about that but I'm trying to avoid ever using those after countless problems. It's the sort of thing thats hard to test, works on my machine, works for one install, then another install of the same software explodes in unexpected ways. I know I'll end up regretting it if I do that, but... at least I now have Sentry so it can catch problems. I'd like to try and do this properly if at all possible, is this not something people ever have to face? |
Beta Was this translation helpful? Give feedback.
-
Eager loading doesn't happen here because of this line: Refer to https://laravel.com/docs/11.x/eloquent#cursors for detail. |
Beta Was this translation helpful? Give feedback.
-
I am using the following formatter and due to the relationships it's lazyloading these relationships on every record (180k of them).
I only have access to the
$model
here which means doing a $load would not help with the next models, so what else can I do?I tried adding
$with
on the Nova resource but that's not helped.With or without that $with this is how the trace looks:
Is there any way to get this Action respecting the
$with
property, or allowing me access to the collection so I can preload/eagerload myself somehow?Beta Was this translation helpful? Give feedback.
All reactions