Skip to content

Commit

Permalink
Fix/eager loading optimizations (#1889)
Browse files Browse the repository at this point in the history
* Solve slow page loading times with 500 subfleets

* revised load to loadMissing

* fix load missing to prevent eager loading

* StyleCI Fixes

* More StyleCI fixes

---------

Co-authored-by: Nabeel S. <nabeelio@users.noreply.github.com>
  • Loading branch information
BossOfGames and nabeelio authored Nov 11, 2024
1 parent 0192625 commit accf667
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Admin/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function aircraftList(?User $user = null): array
$subfleets = $this->userSvc->getAllowableSubfleets($user);
}

$subfleets->loadMissing('aircraft');

foreach ($subfleets as $subfleet) {
$tmp = [];
foreach ($subfleet->aircraft as $ac) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Frontend/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function aircraftList(bool $add_blank = false): array
$aircraft[''] = '';
}

$subfleets->loadMissing('aircraft');

foreach ($subfleets as $subfleet) {
$tmp = [];
foreach ($subfleet->aircraft->when($location_check, function ($query) use ($user_loc) {
Expand Down
2 changes: 2 additions & 0 deletions app/Services/FlightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public function filterSubfleets(User $user, Flight $flight)
$aircraft_not_booked = setting('bids.block_aircraft', false);

if ($aircraft_at_dpt_airport || $aircraft_not_booked) {
$subfleets->loadMissing('aircraft');

foreach ($subfleets as $subfleet) {
$subfleet->aircraft = $subfleet->aircraft->filter(
function ($aircraft, $i) use ($user, $flight, $aircraft_at_dpt_airport, $aircraft_not_booked) {
Expand Down

0 comments on commit accf667

Please sign in to comment.