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

Use eager loading to reduce query load on index pages #92

Closed
uberbrady opened this issue Nov 29, 2013 · 1 comment
Closed

Use eager loading to reduce query load on index pages #92

uberbrady opened this issue Nov 29, 2013 · 1 comment

Comments

@uberbrady
Copy link
Collaborator

On any page that is a list of 'things' - which then refers to any associated sub-things - we should eager-load the sub-things.

This should substantially reduce query load by basically performing a JOIN for us.

You'd notice this more on a page that had a large list of 'things' where it was referring to bits of the sub-things on the each line.

@kds100
Copy link

kds100 commented Jul 23, 2014

Had to add eager loading to solve performance issues with a large set of assets. Here is an example of the altered code for getIndex in the AssetsController.

public function getIndex()
{
// Grab all the assets

    // Filter results
    if (Input::get('Pending'))
    {
        $assets = Asset::orderBy('asset_tag', 'ASC')->whereNull('status_id','and')->where('assigned_to','=','0')->where('physical', '=', 1)->get();
    }
    else if (Input::get('RTD'))
    {
        $assets = Asset::orderBy('asset_tag', 'ASC')->where('status_id', '=', 0)->where('assigned_to','=','0')->where('physical', '=', 1)->get();
    }
    else if (Input::get('Undeployable'))
    {
        $assets = Asset::orderBy('asset_tag', 'ASC')->where('status_id', '>', 1)->where('physical', '=', 1)->get();
    }
    else if (Input::get('Deployed'))
    {
        $assets = Asset::orderBy('asset_tag', 'ASC')->where('status_id', '=', 0)->where('assigned_to','>','0')->where('physical', '=', 1)->get();
    }
    else
    {
        // ADDED Eager Loading params for Model, Assigned User, Asset Location - decreases load time significantly
        // Note the addition of AssetsStatus to complete the loading improvement.
        // Debug Mode still has overhead, but much more manageable
        $assets = Asset::with('model','assigneduser','assetloc','assetstatus')->orderBy('asset_tag', 'ASC')->where('physical', '=', 1)->get();
    }

    // Paginate the users
    /**$assets = $assets->paginate(Setting::getSettings()->per_page)
        ->appends(array(
            'Pending' => Input::get('Pending'),
            'RTD' => Input::get('RTD'),
            'Undeployable' => Input::get('Undeployable'),
            'Deployed' => Input::get('Deployed'),
        ));
    **/

    return View::make('backend/hardware/index', compact('assets'));
}

@buzzedword buzzedword mentioned this issue Sep 8, 2014
@snipe snipe added the 👩‍💻 ready for dev These issues are ready for someone to work on them - take your pick! label Nov 4, 2014
@snipe snipe closed this as completed Nov 5, 2014
@snipe snipe removed the 👩‍💻 ready for dev These issues are ready for someone to work on them - take your pick! label Nov 5, 2014
This was referenced Jul 19, 2016
@ESWBitto ESWBitto mentioned this issue Mar 16, 2017
2 tasks
@d90 d90 mentioned this issue Jun 12, 2019
2 tasks
@rkayutkin rkayutkin mentioned this issue Jun 14, 2019
2 tasks
@Bjufen Bjufen mentioned this issue Feb 9, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants