Ik heb een oplossing - Het is niet elegant, maar erg snel. 1.6s voor 80k-records. Betere oplossingen worden zeer op prijs gesteld.
$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()]);
}
});