Laravel:超过了30秒的最大执行时间,如何优化查询?

时间:2019-10-10 11:37:00

标签: php laravel-5

在地图上有太多请求(最多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());
            }
        }

0 个答案:

没有答案