Throttle recalculating scores.

This commit is contained in:
Matt Young 2025-06-15 14:32:17 -05:00
parent 33bca1cfdf
commit 4f317f1458
1 changed files with 21 additions and 0 deletions

View File

@ -2,9 +2,11 @@
namespace App\Http\Controllers\Tabulation; namespace App\Http\Controllers\Tabulation;
use App\Actions\Tabulation\CalculateAuditionScores;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Audition; use App\Models\Audition;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class SeatingStatusController extends Controller class SeatingStatusController extends Controller
{ {
@ -13,6 +15,24 @@ class SeatingStatusController extends Controller
*/ */
public function __invoke(Request $request) public function __invoke(Request $request)
{ {
if (! Cache::has('seating_status_audition_totaler_throttle')) {
$lock = Cache::lock('seating_status_audition_totaler_lock');
if ($lock->get()) {
try {
$totaler = app(CalculateAuditionScores::class);
foreach (Audition::forSeating()->with('judges')->get() as $audition) {
$totaler($audition);
}
// set throttle
Cache::put('seating_status_audition_totaler_throttle', true, 15);
} finally {
$lock->release();
}
}
}
$auditions = Audition::forSeating() $auditions = Audition::forSeating()
->withCount([ ->withCount([
'entries' => function ($query) { 'entries' => function ($query) {
@ -25,6 +45,7 @@ class SeatingStatusController extends Controller
}, },
]) ])
->with('flags') ->with('flags')
->with('entries')
->get(); ->get();
$auditionData = []; $auditionData = [];
foreach ($auditions as $audition) { foreach ($auditions as $audition) {