Current state with latest updates
This commit is contained in:
+52
-3
@@ -13,7 +13,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Laravel\Scout\SearchableScope;
|
||||
|
||||
@@ -73,6 +72,8 @@ class Artwork extends Model
|
||||
'has_missing_thumbnails',
|
||||
'missing_thumbnail_variants_json',
|
||||
'thumbnails_checked_at',
|
||||
'featured_thumbnail_variants_json',
|
||||
'featured_thumbnails_checked_at',
|
||||
'file_size',
|
||||
'mime_type',
|
||||
'width',
|
||||
@@ -154,6 +155,8 @@ class Artwork extends Model
|
||||
'published_at' => 'datetime',
|
||||
'missing_thumbnail_variants_json' => 'array',
|
||||
'thumbnails_checked_at' => 'datetime',
|
||||
'featured_thumbnail_variants_json' => 'array',
|
||||
'featured_thumbnails_checked_at' => 'datetime',
|
||||
'published_as_type' => 'string',
|
||||
'published_as_id' => 'integer',
|
||||
'publish_at' => 'datetime',
|
||||
@@ -271,18 +274,64 @@ class Artwork extends Model
|
||||
?? 'https://files.skinbase.org/default/missing_xl.webp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit state of `featured_thumbnail_variants_json`, distinguishing "never checked"
|
||||
* from "checked, nothing found":
|
||||
*
|
||||
* - `null` → not audited yet (FeaturedArtworkThumbnailGenerator has never
|
||||
* run plan()/generate() for this artwork).
|
||||
* - `[]` → audited, but no featured variant exists in object storage.
|
||||
* - non-empty string[] → audited; these variant names are known to exist.
|
||||
*
|
||||
* A value that fails to decode as an array (e.g. legacy/malformed data) is treated
|
||||
* the same as `null` — "not audited" — rather than throwing or reporting variants
|
||||
* that were never actually confirmed to exist.
|
||||
*
|
||||
* @return array{status: 'not_audited'|'no_variants'|'available', variants: list<string>}
|
||||
*/
|
||||
public function featuredThumbnailAuditState(): array
|
||||
{
|
||||
$raw = $this->featured_thumbnail_variants_json;
|
||||
|
||||
if (! is_array($raw)) {
|
||||
return ['status' => 'not_audited', 'variants' => []];
|
||||
}
|
||||
|
||||
$variants = array_values(array_filter($raw, 'is_string'));
|
||||
|
||||
if ($variants === []) {
|
||||
return ['status' => 'no_variants', 'variants' => []];
|
||||
}
|
||||
|
||||
return ['status' => 'available', 'variants' => $variants];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a dedicated featured-hero variant is known to exist in object storage.
|
||||
*
|
||||
* This reads precomputed state from `featured_thumbnail_variants_json` (see
|
||||
* `featuredThumbnailAuditState()`) rather than checking the remote disk directly —
|
||||
* remote existence checks must only happen from `FeaturedArtworkThumbnailGenerator`
|
||||
* (admin commands / queued jobs), never during public homepage rendering, since a
|
||||
* live `Storage::exists()` per variant is a synchronous network round trip.
|
||||
*/
|
||||
public function hasFeaturedThumbnail(?string $variant = null): bool
|
||||
{
|
||||
if (empty($this->hash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$known = $this->featuredThumbnailAuditState()['variants'];
|
||||
|
||||
if ($known === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$helper = app(ArtworkFeaturedImagePath::class);
|
||||
$variants = $variant !== null ? [$helper->normalizeVariant($variant)] : $helper->variantNames();
|
||||
$disk = Storage::disk((string) config('uploads.object_storage.disk', 's3'));
|
||||
|
||||
foreach ($variants as $variantName) {
|
||||
if ($disk->exists($helper->objectPath($this, $variantName))) {
|
||||
if (in_array($variantName, $known, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user