Open ababkov opened 6 years ago
Might be worth looking at something like this for async loading (may be easier to reconcile in certain places)... not sure how to reconcile this all back to sync transformers. Something to investigate longer term probably.
Based on what I can see at the moment (i could be wrong - i can't get the demo to fully work for me so i can't be sure), eager loading will only work for the current resource + its immediate includes. Going any more than one level down with includes will still lead to a diluted version of the original N+1 problem.
This issue isn't that urgent - it affects deeply nested includes only and perf issues would likely only be seen on reasonably sized data sets.
This is mostly a brain dump for myself (happy to have thoughts though) to allow for some time to think on this and possible approaches.
For example, for the following include string assuming it's in the context of a top level post model:
id,user{email,id},comments{user{email,id,comments{post{id}}
This breaks out into something like:
post.user, post.comments
- Query Count: 3comments.user
- Query Count: Number of postscomments.user, comments.post
- Query Count: Number of posts + Number of posts * Number of CommentsDealing with eager loading recursively
Dealing with limits, ordering and eager loading
Limits on sub relationships aren't supported in eloquent, something like this might work
posts:(limit:2)
GROUP_CONCAT
has some limitations if you're working with large related limits.SUBSTRING_INDEX(GROUP_CONCAT(id),",",2)
=array_agg(id)[1:2]