2024-08-31 01:19:22 -04:00
|
|
|
<?php
|
|
|
|
|
2025-01-30 00:23:55 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-08-31 01:19:22 -04:00
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\Mod;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
class UpdateModDownloadsJob implements ShouldQueue
|
|
|
|
{
|
2025-01-30 00:23:55 -05:00
|
|
|
use Dispatchable;
|
|
|
|
use InteractsWithQueue;
|
|
|
|
use Queueable;
|
|
|
|
use SerializesModels;
|
2024-08-31 01:19:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalculate the total download counts for each mod.
|
|
|
|
*/
|
|
|
|
public function handle(): void
|
|
|
|
{
|
2025-01-30 00:23:55 -05:00
|
|
|
Mod::with('versions')->chunk(100, function ($mods): void {
|
2024-08-31 01:19:22 -04:00
|
|
|
foreach ($mods as $mod) {
|
|
|
|
$mod->calculateDownloads();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|