I have potentially 500,000 records to either insert or update into my database.
I'm using the updateOrCreate function in Laravel but it's still taking a very long time.
I'm current using a foreach loop wrapped in a database transaction but is there a better solution?
DB::transaction(function() use ($items, $client) {
foreach($items as $item) {
$data = array(
'external_id' => $item->external_id,
'comment' => $item->comment,
'code_id' => $item->code_id,
'client_id' => $client->id
);
Registration::updateOrCreate(
[
'user_id' => $item->user_id,
'date' => Carbon::parse($item->date)->format('Y-m-d'),
'session' => $item->session
],
$data
);
}
});