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,45 @@
<?php
declare(strict_types=1);
namespace App\Services\Vision;
use App\Models\Artwork;
use App\Models\Category;
final class ArtworkVectorMetadataService
{
/**
* @return array{content_type: string, category: string, user_id: string, tags: list<string>}
*/
public function forArtwork(Artwork $artwork): array
{
$artwork->loadMissing([
'categories' => fn ($categories) => $categories->with('contentType')->orderBy('sort_order')->orderBy('name'),
'tags:id,slug',
]);
$category = $this->primaryCategory($artwork);
return [
'content_type' => (string) ($category?->contentType?->name ?? ''),
'category' => (string) ($category?->name ?? ''),
'user_id' => (string) ($artwork->user_id ?? ''),
'tags' => $artwork->tags
->pluck('slug')
->map(static fn (mixed $slug): string => trim((string) $slug))
->filter(static fn (string $slug): bool => $slug !== '')
->unique()
->values()
->all(),
];
}
private function primaryCategory(Artwork $artwork): ?Category
{
/** @var Category|null $category */
$category = $artwork->categories->sortBy('sort_order')->first();
return $category;
}
}