i have in my Laravel App this code: i read every line in a .csv file and a want to update a value. But the multiple's update query are very slow with a .csv of 8k rows. How i can speed this code ? Thanks
DB::beginTransaction();
try {
$delimiter = ",";
$firstLine = true;
if ($handle !== FALSE) {
$position = 1;
while (($csv_line = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
if ($firstLine == true) {
$firstLine = false;
continue;
}
$player_uid = $csv_line[0];
DB::table('scores')
->where('season_uid', $season_uid)
->where('day', $day)
->where('player_uid', $player_uid)
->update(['position' => $position]);
$position++;
}
fclose($handle);
}
DB::commit();
return true;
} catch (\Exception $e) {
Log::error($e);
DB::rollBack();
return false;
}