jeudi 10 octobre 2019

Laravel: Maximum execution time of 30 seconds exceeded, how to optimize query?

There are too many requests on the map (up to 15000) to load the page, probably due to the fact that they search for 1 by 1 products instead of taking them all at once. Take the whole relationship where the problem is? Error:

* @return mixed
 *
 * @throws \Illuminate\Database\QueryException
 */
protected function runQueryCallback($query, $bindings, Closure $callback)
{
    // To execute the statement, we'll simply call the callback, which will actually
    // run the SQL against the PDO connection. Then we can calculate the time it
    // took to execute and log the query SQL, bindings and time in our memory.
    try {
        $result = $callback($this, $query, $bindings);
    }

    // If an exception occurs when attempting to run a query, we'll format the error
    // message to include the bindings with SQL, which will make this exception a
    // lot more helpful to the developer instead of just the database's errors.
    catch (Exception $e) {
        throw new QueryException(
            $query, $this->prepareBindings($bindings), $e
        );
    }

    return $result;
}

   My route: Route::get('/map', ['as' => 'map', 'uses' => 'Home\HomeController@map']);
    class HomeController extends Controller
    {
            private $gasStationRepo;
            private $gasStationBrandsRepo;
            private $mapContentRepo;

           ContactMessageRepository {
                        $this->gasStationRepo = $gasStationRepo;
                        $this->gasStationBrandsRepo = $gasStationBrandsRepo;
                        $this->mapContentRepo = $mapContentRepo;
                }

         ... 
         public function map()
            {

                return view('map')
                        ->with('mapContent', $this->mapContentRepo->first())
                        ->with('locations_eko', $this->gasStationBrandsRepo->getStations('eko'))
                        ->with('locations_petrol', $this->gasStationBrandsRepo->getStations('petrol'))
                        ->with('locations_kruiz', $this->gasStationBrandsRepo->getStations('kruiz'))
                        ->with('locations_lukoil', $this->gasStationBrandsRepo->getStations('lukoil'))
                        ->with('gasStations', $this->gasStationRepo->all());
            }
        }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire