optimizations

This commit is contained in:
2026-03-28 19:15:39 +01:00
parent 0b25d9570a
commit cab4fbd83e
509 changed files with 1016804 additions and 1605 deletions

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Models\Collection;
use App\Models\User;
use App\Services\CollectionHistoryService;
use App\Services\CollectionRankingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
final class RefreshCollectionRecommendationJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public int $tries = 3;
/** @var array<int, int> */
public array $backoff = [30, 180, 600];
public function __construct(
public readonly int $collectionId,
public readonly ?int $actorUserId = null,
public readonly string $context = 'default',
) {
$this->onQueue((string) config('collections.v5.queue.name', 'collections'));
}
public function handle(CollectionRankingService $ranking): void
{
$collection = Collection::query()->find($this->collectionId);
if (! $collection) {
return;
}
$actor = $this->actorUserId ? User::query()->find($this->actorUserId) : null;
$fresh = $ranking->refresh($collection, $this->context);
app(CollectionHistoryService::class)->record(
$fresh,
$actor,
'recommendation_refreshed',
'Collection recommendations refreshed.',
null,
[
'context' => $this->context,
'recommendation_tier' => $fresh->recommendation_tier,
'ranking_bucket' => $fresh->ranking_bucket,
'search_boost_tier' => $fresh->search_boost_tier,
]
);
}
}