toDateTimeString(); $ranking->artworkSignalsQuery() ->orderBy('a.id') ->chunk(self::CHUNK_SIZE, function ($rows) use ($ranking, $modelVersion, $now, &$total): void { $rows = collect($rows); if ($rows->isEmpty()) { return; } $upserts = $rows->map(function ($row) use ($ranking, $modelVersion, $now): array { $scores = $ranking->computeScores($row); return [ 'artwork_id' => (int) $row->id, 'score_trending' => $scores['score_trending'], 'score_new_hot' => $scores['score_new_hot'], 'score_best' => $scores['score_best'], 'model_version' => $modelVersion, 'computed_at' => $now, ]; })->all(); DB::table('rank_artwork_scores')->upsert( $upserts, ['artwork_id'], // unique key ['score_trending', 'score_new_hot', 'score_best', // update these 'model_version', 'computed_at'] ); $total += count($upserts); }); Log::info('RankComputeArtworkScoresJob: finished', [ 'total_updated' => $total, 'model_version' => $modelVersion, ]); } }