Laravel: Превышено максимальное время выполнения 30 секунд, как оптимизировать запрос? - PullRequest
0 голосов
/ 10 октября 2019

На карте слишком много запросов (до 15000) для загрузки страницы, возможно, из-за того, что они ищут продукты 1 на 1, а не принимают их все сразу. Возьми целые отношения, где проблема? Ошибка:

* @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());
            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...