当我循环数据时,我遇到了问题,它将显示504网关超时。
时间表表: 15,000条记录
雇员表: 400项记录
人力表:10万项记录。
如果我在SQL中得到3个表,只需0.1ms。我的案子还有其他解决办法吗?谢谢大家。
$timesheets = Timesheets::where('type', 'Overtime')->get();
foreach ($timesheets as $key => $value) {
if (!empty($employeesUuid = Employees::where('employees_number', $value->employees_id)->first()->employees_uuid)) {
$date = Carbon::parse($value->start_dt)->format('Y-m-d');
$manpower = Manpower::with('pwra.purchaseOrder')
->where('employees_uuid', $employeesUuid)
->whereDate('register_date', $date)
->first();
// What I want
if (!empty($manpower)) {
$timesheets[$key]->po_number = $manpower->pwra->purchaseOrder->first()->po_number;
}
}
}发布于 2021-08-02 07:18:13
首先,为什么不使用关系hasOneThrough或hasManyThrough来表示Timesheet和Manpower。您还可以在TimeSheet和Employee之间建立关系。https://laravel.com/docs/6.x/eloquent-relationships#has-one-through https://laravel.com/docs/6.x/eloquent-relationships#has-many-through
504网关超时错误与内存泄漏无关。它与服务器响应有关,这可能是由于互联网薄弱或任何代码问题造成的。https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504
除此之外,如果您认为内存泄漏并破坏了系统,则可以延迟收集来保存内存。
https://stackoverflow.com/questions/68615715
复制相似问题