thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

do not query 'select * from data_types' in api route. #5723

Closed devwithu closed 1 year ago

devwithu commented 1 year ago

Laravel version

8.83.27

PHP version

7.4.33

Voyager version

1.6.0

Description of problem

I have a site with high traffic in api call. I used voyager to manage admin contents. but I noticed that its running a single query more than millions of times in my api call. the query is select * from data_types

I want to do not query select * from data_types in my api route.

Please suggest how can I solve the issue.

i read #3396 , #5244.

Proposed solution

I want to do not query select * from data_types in my api route.

Please suggest how can I solve the issue.

i read #3396 , #5244.

maybe cache, or do not process some voyager logic(select * from data_types) for api route.

Alternatives considered

No response

Additional context

No response

devwithu commented 1 year ago

vendor/tcg/voyager/routes/voyager.php maybe this line 39. .... foreach (Voyager::model('DataType')::all() as $dataType) {

devwithu commented 1 year ago

web.php if(Str::contains(Request::getPathInfo(), '/admin')){ Route::group(['prefix' => 'admin'], function () { Voyager::routes(); }); }

and fix the problem. and now do not query 'select * from data_types' in api route

fletch3555 commented 1 year ago

You should be caching your routes in a production environment, which would prevent that call from happening

devwithu commented 1 year ago

wow. thank you very much @fletch3555 . i didn't know about cache route. i will study this.

https://laravel.com/docs/9.x/routing#route-caching https://stackoverflow.com/questions/37878951/how-to-clear-laravel-route-caching-on-server

have a nice day.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.