ervin_b
ervin_b

Reputation: 57

how to speed up laravel?

I have a PHP Application and I use Laravel Framework. When I'm developing the application its response time is not an issue. But, when I deployed it and it gets a lot of data in one of its transaction table (almost 7,000 rows as of this time) in the database it takes of almost 6 seconds to refresh the page. I only get the last 100 data from the database to view as logs. Is there such ways to shorten this response time? BTW my application only run in a local network.

Here is my code:

Route::get('/', function()
{
    $users = DB::table('logs')
        ->join('students', 'logs.id', '=', 'students.id')
        ->orderBy('time_in', 'desc')
        ->take(100)
        ->get();

    return View::make('index')
        ->with('users',$users);
});

Upvotes: 0

Views: 758

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44874

You should always be checking the query health using explain select..

Now from the query that you have in the query builder you will need some indices if not alreay applied

alter table logs add index id_idx(id) ; 

If id is a primary key in logs table then you do not need the above index

alter table logs add index time_in_idx(time_in);

The above will be helpful for ordering the data .

If id is not a primary key and not indexed either then you may just add the following covering index

alter table logs add index id_time_idx(id,time_in);

Upvotes: 1

Related Questions