Ich habe eine Lösung - Es ist nicht elegant, aber sehr schnell. 1,6 s für 80.000 Datensätze. Bessere Lösungen wären sehr willkommen.
$allResults = [
['id' => 1, 'rank' => 100],
['id' => 2, 'rank' => 99],
['id' => 3, 'rank' => 102],
...
['id' => 80000, 'rank' => 3],
];
$rankings = [];
foreach ($allResults as $result) {
$rankings[] = implode(', ', ['"' . $result['id'] . '"', $result['rank']]);
}
$rankings = Collection::make($rankings);
$rankings->chunk(500)->each(function($ch) {
$rankingString = '';
foreach ($ch as $ranking) {
$rankingString .= '(' . $ranking . '), ';
}
$rankingString = rtrim($rankingString, ", ");
try {
\DB::insert("INSERT INTO my_rankings (`id`, `rank`) VALUES $rankingString ON DUPLICATE KEY UPDATE `rank`=VALUES(`rank`)");
} catch (\Exception $e) {
print_r([$e->getMessage()]);
}
});