optimizations
This commit is contained in:
@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use App\Services\ThumbnailService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Scout\Searchable;
|
||||
@@ -27,6 +26,10 @@ class Artwork extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, Searchable;
|
||||
|
||||
public const VISIBILITY_PUBLIC = 'public';
|
||||
public const VISIBILITY_UNLISTED = 'unlisted';
|
||||
public const VISIBILITY_PRIVATE = 'private';
|
||||
|
||||
protected $table = 'artworks';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -44,11 +47,23 @@ class Artwork extends Model
|
||||
'width',
|
||||
'height',
|
||||
'is_public',
|
||||
'visibility',
|
||||
'is_approved',
|
||||
'is_mature',
|
||||
'published_at',
|
||||
'hash',
|
||||
'thumb_ext',
|
||||
'file_ext',
|
||||
'clip_tags_json',
|
||||
'blip_caption',
|
||||
'yolo_objects_json',
|
||||
'vision_metadata_updated_at',
|
||||
'last_vector_indexed_at',
|
||||
'ai_status',
|
||||
'title_source',
|
||||
'description_source',
|
||||
'tags_source',
|
||||
'category_source',
|
||||
// Versioning
|
||||
'current_version_id',
|
||||
'version_count',
|
||||
@@ -62,9 +77,20 @@ class Artwork extends Model
|
||||
|
||||
protected $casts = [
|
||||
'is_public' => 'boolean',
|
||||
'visibility' => 'string',
|
||||
'is_approved' => 'boolean',
|
||||
'is_mature' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'publish_at' => 'datetime',
|
||||
'clip_tags_json' => 'array',
|
||||
'yolo_objects_json' => 'array',
|
||||
'vision_metadata_updated_at' => 'datetime',
|
||||
'last_vector_indexed_at' => 'datetime',
|
||||
'ai_status' => 'string',
|
||||
'title_source' => 'string',
|
||||
'description_source' => 'string',
|
||||
'tags_source' => 'string',
|
||||
'category_source' => 'string',
|
||||
'version_updated_at' => 'datetime',
|
||||
'requires_reapproval' => 'boolean',
|
||||
];
|
||||
@@ -156,6 +182,14 @@ class Artwork extends Model
|
||||
return $this->belongsToMany(Category::class, 'artwork_category', 'artwork_id', 'category_id');
|
||||
}
|
||||
|
||||
public function collections(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Collection::class, 'collection_artwork', 'artwork_id', 'collection_id')
|
||||
->withPivot(['order_num'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('order_num');
|
||||
}
|
||||
|
||||
public function tags(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tag::class, 'artwork_tag', 'artwork_id', 'tag_id')
|
||||
@@ -218,6 +252,11 @@ class Artwork extends Model
|
||||
return $this->belongsTo(ArtworkVersion::class, 'current_version_id');
|
||||
}
|
||||
|
||||
public function artworkAiAssist(): HasOne
|
||||
{
|
||||
return $this->hasOne(ArtworkAiAssist::class, 'artwork_id');
|
||||
}
|
||||
|
||||
public function awardStat(): HasOne
|
||||
{
|
||||
return $this->hasOne(ArtworkAwardStat::class);
|
||||
@@ -267,6 +306,17 @@ class Artwork extends Model
|
||||
'category' => $category,
|
||||
'content_type' => $content_type,
|
||||
'tags' => $tags,
|
||||
'ai_clip_tags' => collect((array) ($this->clip_tags_json ?? []))
|
||||
->map(static fn ($row) => is_array($row) ? (string) ($row['tag'] ?? '') : '')
|
||||
->filter()
|
||||
->values()
|
||||
->all(),
|
||||
'ai_blip_caption' => (string) ($this->blip_caption ?? ''),
|
||||
'ai_yolo_objects' => collect((array) ($this->yolo_objects_json ?? []))
|
||||
->map(static fn ($row) => is_array($row) ? (string) ($row['tag'] ?? '') : '')
|
||||
->filter()
|
||||
->values()
|
||||
->all(),
|
||||
'resolution' => $resolution,
|
||||
'orientation' => $orientation,
|
||||
'downloads' => (int) ($stat?->downloads ?? 0),
|
||||
@@ -276,6 +326,7 @@ class Artwork extends Model
|
||||
'is_public' => (bool) $this->is_public,
|
||||
'is_approved' => (bool) $this->is_approved,
|
||||
// ── Trending / discovery fields ────────────────────────────────────
|
||||
'trending_score_1h' => (float) ($this->trending_score_1h ?? 0),
|
||||
'trending_score_24h' => (float) ($this->trending_score_24h ?? 0),
|
||||
'trending_score_7d' => (float) ($this->trending_score_7d ?? 0),
|
||||
'favorites_count' => (int) ($stat?->favorites ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user