php - Eloquent logic refactor -


today came legacy code. have function generates long runtimes , occurs timeout @ our partner. function checks reserved seats @ theatre instead of data , check empty seats runs query every single seat. (i think) generates huge runtime.

here correspondig code:

public function printticketchaos(){          $input = input::all();          if( isset($input['date_id']) && !isset($input['reserve_id']) ){             $program_date = \model\programdate::find($input['date_id']);             if($input['piece'] > $program_date->available_capacity){                 //dd($input['piece'] . ' ??? ' . $program_date->available_capacity);                 return true;             }              $reserved_seats = session::get('reserved_seats');              if($reserved_seats != null && count($reserved_seats) > 0){                 foreach ($reserved_seats $row => $seats) {                     foreach ($seats $key => $seat) {                          $reserve = \model\reserve::whereforeigndateid($program_date->id)->wheretablename('programs')->wherehas('seats', function($query) use($row, $seat){ $query->whererow($row)->whereseat($seat); })->first();                          if($reserve != null){                             return true;                         }                         $oi = \model\orderitem::whereforeignid($program_date->id)->wheretablename('programs')->wherehas('order', function($query){ $query->wherestorno(0); })->wherehas('seats', function($query) use($row, $seat){ $query->whererow($row)->whereseat($seat); })->first();                         if($oi != null){                             return true;                         }                     }                 }             }         }           return false;     } 

i think solution query seats , check empty ones in foreach. idea or think best way it?

the code uses laravel 4.2

thank aswers!

okay, made changes in query , logic aswell still slow hell. system uses 3rd party pdf generator create "ticket" costumer , "bad guy".


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -