when execute this code getting 504 error in AWS server
$query = User::with([
'userDetails',
'customer.customerInfomation.customerHistory',
])->where('KSTATUS', $kstatus);
in userDetails and customer relationship get more than 100k data raws.This work in local server but when this query execute in AWS dev environment getting 504 error.i want to fix this without increasing memory size or using chunk().Can anyone give me a suggestions to fix this.
CodePudding user response:
See the laravel documentation on chunking:
use Illuminate\Support\Facades\DB;
DB::table('users')->orderBy('id')->chunk(100, function ($users) {
foreach ($users as $user) {
//
}
});
This might help you to perform the operation you are looking for in chunks even if you have more than 10 million records in db you can pocess it this way for your use case.
You should be chunking results when working with large data sets. This allows you to process smaller loads, reduces memory consumption and allows you to return data to the User while the rest is being fetched/processing.
CodePudding user response:
DB Query DB Query is More Faster then Eloquent. DB Query Speed Fast Even SQL Query. So I think Solution is QB Query. DB Query Is Most Fast Then SQL Query then Eloquent