mardi 5 mars 2019

Laravel MySQL select with limit

I'm trying to show the 20 latest entry from a table in my database. This table has about 10,000 rows and the page that wants to load the latest 20 takes up to 12 seconds to respond and load.... the page it self loads fast but before showing the page the screen is white and takes about 11-12 seconds then shows the page... only this page has this problem and it seems it loads all the entries and then tries to cut the last 20... I don't know I wanted to ask if there is anything wrong with this code? or is there an alternative way to select from mysql db?

$entries = User::where(['user_type' => 'writer', 'status' => 'active', 'mobile'=>'on','city'=>$city_id])->orderBy("created_at","Desc")->limit(20)->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire