Skip to content
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

Lazy Loading issues across the package #79

Open
Preshiousy1 opened this issue Jul 15, 2022 · 2 comments
Open

Lazy Loading issues across the package #79

Preshiousy1 opened this issue Jul 15, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Preshiousy1
Copy link

There are a number of lazy loading issues across the package that start to arise once I have added more than one post, you are calling model relationships within views which is not ideal, it should be called with a YourModel::with('relation')->get() before passing into the view. I know I could turn off lazy loading but that is not ideal for performance.

An example is line 58 of your NinshopsAdmin Controller. looks like this:
$posts = BinshopsPostTranslation::orderBy("post_id", "desc")->where('lang_id', $language_id) ->paginate(10);

should be this:

$posts = BinshopsPostTranslation::with(['post'])->orderBy("post_id", "desc")->where('lang_id', $language_id) ->paginate(10);

as you are calling $post->post->name in the view, there are a number of other instances as well.

Screenshot 2022-07-15 at 15 07 17

@samberrry samberrry added the enhancement New feature or request label Dec 28, 2022
@samberrry
Copy link
Member

@Preshiousy1 thanks for your suggestion, yes it causes N+1 query problem. It comes from the translation structure, may be we need a refactor, or going back to the single language to keep the package structure simple, because the current multi lang structure make package structure a little complex.

Anyway, thanks for your constructive report.

@samberrry
Copy link
Member

I tried to monitor queries using this tool: https://github.com/supliu/laravel-query-monitor

experiments:
1- call for http://127.0.0.1:8000/blog -> 10 queries used - > 1 post
2- call for http://127.0.0.1:8000/blog -> 12 queries used - > 2 posts

experiment 1:
https://user-images.githubusercontent.com/20775532/209834122-6885477d-e2aa-492f-a295-e6cafabe3c5c.mp4

experiment 2:

exp2.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants