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,50 @@
<?php
declare(strict_types=1);
namespace App\Services\NovaCards;
use App\Models\NovaCard;
use App\Models\User;
class NovaCardLineageService
{
public function __construct(
private readonly NovaCardPresenter $presenter,
) {
}
public function resolve(NovaCard $card, ?User $viewer = null): array
{
$trailCards = [];
$cursor = $card;
$visited = [];
while ($cursor && ! in_array($cursor->id, $visited, true)) {
$visited[] = $cursor->id;
$trailCards[] = $cursor;
$cursor = $cursor->originalCard?->loadMissing(['user.profile', 'category', 'template', 'backgroundImage', 'tags', 'originalCard.user', 'rootCard.user']);
}
$trailCards = array_reverse($trailCards);
$rootCard = $card->rootCard ?? ($trailCards[0] ?? $card);
$family = NovaCard::query()
->with(['user.profile', 'category', 'template', 'backgroundImage', 'tags', 'originalCard', 'rootCard'])
->where(function ($query) use ($rootCard): void {
$query->where('id', $rootCard->id)
->orWhere('root_card_id', $rootCard->id)
->orWhere('original_card_id', $rootCard->id);
})
->published()
->orderByDesc('published_at')
->get();
return [
'card' => $this->presenter->card($card, false, $viewer),
'trail' => $this->presenter->cards($trailCards, false, $viewer),
'root_card' => $this->presenter->card($rootCard, false, $viewer),
'family_cards' => $this->presenter->cards($family, false, $viewer),
];
}
}