Php 拉威尔雄辩的负载缓慢
有很多类似的话题,但我找不到解决方案。此查询加载速度非常慢Php 拉威尔雄辩的负载缓慢,php,laravel-5.6,Php,Laravel 5.6,有很多类似的话题,但我找不到解决方案。此查询加载速度非常慢 public function getAllBids() { return Bid::with('user', 'group') ->join('auct_lots', function ($join) { $join->on('bids.lot_id', '=', 'auct_lots.lot_id') ->where('auc
public function getAllBids()
{
return Bid::with('user', 'group')
->join('auct_lots', function ($join) {
$join->on('bids.lot_id', '=', 'auct_lots.lot_id')
->where('auct_lots.company', 'LIKE', '%' . request('brand') . '%')
->where('auct_lots.model_name', 'LIKE', '%' . request('models') . '%')
->where('auct_lots.grade_en', 'LIKE', '%' . request('carGrade') . '%')
->where('auct_lots.auction_name', 'LIKE', '%' . request('auctions') . '%')
->where('auct_lots.model_type_en', 'LIKE', '%' . request('chassis') . '%')
->where('auct_lots.bid', 'LIKE', '%' . request('lots') . '%')
->where('auct_lots.lot_date', 'LIKE', '%' . request('date') . '%');
})
->orderBy('auct_lots.' . request('order_column'), request('order_type'))
->paginate(30);
}
我认为问题在于拍卖场有超过40000张记录。。。但我不知道如何重构此代码以更快地工作。当您拥有大量数据时,最好使用服务器端缓存。这将更快地提高性能 步骤1:为缓存中的存储值创建特征并写入逻辑。 例: 现在在控制器中调用此方法,这将返回数据集合。因此,您不需要一直运行sql查询来获取数据。此方法仅在一次之后运行查询。之后,数据将存储在缓存中,以便从缓存文本文件获取数据的集合 注意:无论何时更新数据,请不要忘记删除此缓存
您也可以将where条件应用于laravel收集,或者您可以使用收集的筛选方法来实现更多的筛选逻辑。不要一次获取40000条记录,只需获取50或100条记录并使用分页。@C2486我不确定我是否理解您的意思…@DmitryMarys他的意思是获取40000条记录会很费力,这就是为什么Laravel有一个称为分页的功能,它允许你做一些事情,比如有一个“下一页”和“上一页”,用于将所有结果分块成可管理的部分。您可以在此处阅读:
trait Student{
public function storeStudentDataInCache(){
$students = Cache::rememberForever('studentList', function () {
return Student::
with(['class', 'exams'])
->where('is_published', 1)->orderBy('display_sequence', 'ASC')->get();
});
return $students;
}
}